<commit_before>#!/usr/bin/env python
"""check-config.py -- VisionEgg configuration check

Run this program first to check the installation status or version
number of the Vision Egg.

"""

import sys, string, os, traceback

# Mac OS X weirdness:

gui_ok = 1

if sys.platform == 'darwin':

    try:
        if not os.path.isabs(sys.argv[0]):
            
            print """Mac OS X - It appears you are running this script
            from the commandline -- turning off GUIs."""
            
            gui_ok = 0
    except Exception, x:
        raise
    print

# sys.stdout and sys.stderr hard to see:

if sys.platform in ['darwin','mac','win32'] and gui_ok:
    try:
        import Tkinter
        class showwarning(Tkinter.Frame):
            def format_string(self,in_str):
                min_line_length = 65
                in_list = string.split(in_str)
                out_str = ""
                cur_line = ""
                for word in in_list:
                    cur_line = cur_line + word + " "
                    if len(cur_line) > min_line_length:
                        out_str = out_str + cur_line[:-1] + "\n"
                        cur_line = ""
                out_str = out_str + cur_line
                return out_str
            def close_window(self,dummy_arg=None):
                #self.destroy()
                self.winfo_toplevel().destroy()
            def __init__(self,title="Vision Egg Warning",message=None):
                Tkinter.Frame.__init__(self,borderwidth=20)
                #self.focus_force()
                self.pack()
                self.winfo_toplevel().title(title)
                Tkinter.Label(self,text=self.format_string(message)).pack()
                b = Tkinter.Button(self,text="OK",command=self.close_window)
                b.pack()
                b.focus_force()
                b.bind('<Return>',self.close_window)
                self.mainloop()
        if sys.platform == 'darwin':
            
            add_str = """ To see this information, run the utility
            'Console' in the 'Applications/Utilities' Folder."""
            
        elif sys.platform == 'win32':
            
            add_str = """ After this script has finished, a second GUI
            window will appear.  Until the second window is closed,
            the console will be available for viewing."""

        else:
            
            add_str = """ Information specific to your platform has
            not been written yet."""
            
        showwarning(title="Conole location warning",
                    message=
                    
            """This script displays information on the console, which
            is not readily visible on this platform."""+add_str)
        
    except:
        print "(Failed to open dialog box-- is Tkinter installed?)"

# Import
unknown_import_fail = 0

try:
    import VisionEgg
except ImportError:
    print """Could not import the VisionEgg module.
    
    This is probably because it is not yet installed.
    
    Try installing by running 'python setup.py install' from the
    command line (as root if necessary).

    The exception raised was:"""
    traceback.print_exc()
except AttributeError, x:
    try:
        def my_import(name):
            mod = __import__(name)
            components = string.split(name, '.')
            for comp in components[1:]:
                mod = getattr(mod, comp)
                return mod
        mod = my_import("VisionEgg.VisionEgg")
        if mod.__name__ == "VisionEgg.VisionEgg":
            print """            **********************************************************
            YOU APPEAR TO HAVE AN OLD COPY OF THE VISION EGG INSTALLED

            Please remove the old installation directory and re-install.

            The old installation directory is %s
            **********************************************************"""%(os.path.abspath(os.path.dirname(mod.__file__)),)
        else:
            unknown_import_fail = 1
    except:
        unknown_import_fail = 1
except:
    unknown_import_fail = 1

if unknown_import_fail:
    print """Could not import the VisionEgg module for an unknown reason.
    
    The exception raised was:"""
    traceback.print_exc()

# Finally, do it!

if 'VisionEgg' in globals().keys():
    print "VisionEgg version %s"%(VisionEgg.release_name,)
    print
    if VisionEgg.config.VISIONEGG_CONFIG_FILE:
        print "Config file found at %s"%(VisionEgg.config.VISIONEGG_CONFIG_FILE,)
    else:
        configuration_src = '<unable to find>'
        try:
            import VisionEgg.Configuration
            configuration_src = VisionEgg.Configuration.__file__
        except:
            pass
        print "No config file found, using defaults from file %s"%(configuration_src,)

    print
    for configname in dir(VisionEgg.config):
        if configname[:2] != '__':
            print configname + " = " + str(getattr(VisionEgg.config,configname))
    print

    if sys.executable != sys.argv[0]:
        # Not running as binary executable in own demo directory
        print "The demo files should be in %s"%(os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,'demos'),)
        print

    # These things have been removed from the installed library directory.<commit_msg>Better checking for old config files.<commit_after>#!/usr/bin/env python
"""check-config.py -- VisionEgg configuration check

Run this program first to check the installation status or version
number of the Vision Egg.

"""

import sys, string, os, traceback
__cvs__ = string.split('$Revision$')[1]
__date__ = string.join(string.split('$Date$')[1:3], ' ')
__author__ = '<NAME> <<EMAIL>>'

# Mac OS X weirdness:

gui_ok = 1

print "check-config.py for Vision Egg 0.9.2."
print "[%s CVS revision %s]"%(__date__,__cvs__)
print "Beginning configuration check."

if sys.platform == 'darwin':

    try:
        if not os.path.isabs(sys.argv[0]):
            
            print """Mac OS X - It appears you are running this script
            from the commandline -- turning off GUIs."""
            
            gui_ok = 0
    except Exception, x:
        raise
    print

# sys.stdout and sys.stderr hard to see:

if sys.platform in ['darwin','mac','win32'] and gui_ok:
    try:
        import Tkinter
        class showwarning(Tkinter.Frame):
            def format_string(self,in_str):
                min_line_length = 65
                in_list = string.split(in_str)
                out_str = ""
                cur_line = ""
                for word in in_list:
                    cur_line = cur_line + word + " "
                    if len(cur_line) > min_line_length:
                        out_str = out_str + cur_line[:-1] + "\n"
                        cur_line = ""
                out_str = out_str + cur_line
                return out_str
            def close_window(self,dummy_arg=None):
                #self.destroy()
                self.winfo_toplevel().destroy()
            def __init__(self,title="Vision Egg Warning",message=None):
                Tkinter.Frame.__init__(self,borderwidth=20)
                #self.focus_force()
                self.pack()
                self.winfo_toplevel().title(title)
                Tkinter.Label(self,text=self.format_string(message)).pack()
                b = Tkinter.Button(self,text="OK",command=self.close_window)
                b.pack()
                b.focus_force()
                b.bind('<Return>',self.close_window)
                self.mainloop()
        if sys.platform == 'darwin':
            
            add_str = """ To see this information, run the utility
            'Console' in the 'Applications/Utilities' Folder."""
            
        elif sys.platform == 'win32':
            
            add_str = """ After this script has finished, a second GUI
            window will appear.  Until the second window is closed,
            the console will be available for viewing."""

        else:
            
            add_str = """ Information specific to your platform has
            not been written yet."""
            
        showwarning(title="Conole location warning",
                    message=
                    
            """This script displays information on the console, which
            is not readily visible on this platform."""+add_str)
        
    except:
        print "(Failed to open dialog box-- is Tkinter installed?)"

# Import
unknown_import_fail = 0

import ConfigParser # If this line fails, you have an old version of Python.

try:
    import VisionEgg
except ImportError:
    print """Could not import the VisionEgg module.
    
    This is probably because it is not yet installed.
    
    Try installing by running 'python setup.py install' from the
    command line (as root if necessary).

    The exception raised was:"""
    traceback.print_exc()
except AttributeError, x:
    if str(x) != "'module' object has no attribute 'release_name'":
        unknown_import_fail = 1
        traceback.print_exc()
    else:
        try:
            def my_import(name):
                mod = __import__(name)
                components = string.split(name, '.')
                for comp in components[1:]:
                    mod = getattr(mod, comp)
                    return mod
            mod = my_import("VisionEgg.VisionEgg")
            if mod.__name__ == "VisionEgg.VisionEgg":
                print """**********************************************************
YOU APPEAR TO HAVE AN OLD COPY OF THE VISION EGG INSTALLED

Please remove the old installation directory and re-install.

The old installation directory is %s
**********************************************************"""%(os.path.abspath(os.path.dirname(mod.__file__)),)
            else:
                unknown_import_fail = 1
                traceback.print_exc()
        except:
            unknown_import_fail = 1
            traceback.print_exc()
except (ConfigParser.MissingSectionHeaderError, ConfigParser.NoSectionError):
        print """**********************************************************
YOU APPEAR TO HAVE AN OLD OR BROKEN COPY "VisionEgg.cfg" INSTALLED

Please remove or rename the the file at the location specified above
and re-install.

The file name and location should be printed above.
**********************************************************"""

except:
    unknown_import_fail = 1
    traceback.print_exc()

if unknown_import_fail:
    print """**********************************************************

Could not import the VisionEgg module for an unknown reason.  See the
traceback printed above.

**********************************************************"""

# Finally, do it!

if 'VisionEgg' in globals().keys():
    print "VisionEgg version %s"%(VisionEgg.release_name,)
    print
    if VisionEgg.config.VISIONEGG_CONFIG_FILE:
        print "Config file found at %s"%(VisionEgg.config.VISIONEGG_CONFIG_FILE,)
    else:
        configuration_src = '<unable to find>'
        try:
            import VisionEgg.Configuration
            configuration_src = VisionEgg.Configuration.__file__
        except:
            pass
        print "No config file found, using defaults from file %s"%(configuration_src,)

    print
    for configname in dir(VisionEgg.config):
        if configname[:2] != '__':
            print configname + " = " + str(getattr(VisionEgg.config,configname))
    print

    if sys.executable != sys.argv[0]:
        # Not running as binary executable in own demo directory
        print "The demo files should be in %s"%(os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,'demos'),)
        print

    # These things have been removed from the installed library directory.
{'fraction_non_alphanumeric': 0.1276523221133362, 'fraction_numerical': 0.0038346825734980826, 'mean_word_length': 2.0835522858644246, 'pattern_counts': {'":': 3, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1251106', 'n_tokens_mistral': 3243, 'n_tokens_neox': 3094, 'n_words': 932}