Пример #1
0
def save():
    """Saves FileDirectives into ConfigFile."""
    section = "*"
    module = sys.modules[__name__]
    parser = RawConfigParser()
    parser.optionxform = str # Force case-sensitivity on names
    parser.add_section(section)
    try:
        f, fname = open(ConfigFile, "wb"), util.longpath(ConfigFile)
        f.write("# %s configuration autowritten on %s.\n" %
                (fname, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
        for name in FileDirectives:
            try:
                parser.set(section, name, json.dumps(getattr(module, name)))
            except Exception: pass
        for name in OptionalFileDirectives:
            try:
                value = getattr(module, name, None)
                if OptionalFileDirectiveDefaults.get(name) != value:
                    parser.set(section, name, json.dumps(value))
            except Exception: pass
        parser.write(f)
        f.close()
    except Exception:
        pass # Fail silently
Пример #2
0
def save():
    """Saves FileDirectives into ConfigFile."""
    section = "*"
    module = sys.modules[__name__]
    parser = RawConfigParser()
    parser.optionxform = str  # Force case-sensitivity on names
    parser.add_section(section)
    try:
        f, fname = open(ConfigFile, "wb"), util.longpath(ConfigFile)
        f.write("# %s %s configuration written on %s.\n" %
                (Title, Version,
                 datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))
        for name in FileDirectives:
            try:
                parser.set(section, name, json.dumps(getattr(module, name)))
            except Exception:
                pass
        for name in OptionalFileDirectives:
            try:
                value = getattr(module, name, None)
                if OptionalFileDirectiveDefaults.get(name) != value:
                    parser.set(section, name, json.dumps(value))
            except Exception:
                pass
        parser.write(f)
        f.close()
    except Exception:
        pass  # Fail silently
Пример #3
0
 def write(self, text):
     """
     Prints text to console window. GUI application will need to attach to
     the calling console, or launch a new console if not available.
     """
     global window
     if not window and win32console:
         if not ConsoleWriter.is_loaded and not ConsoleWriter.handle:
             try:
                 win32console.AttachConsole(-1)  # pythonw.exe from console
                 atexit.register(lambda: ConsoleWriter.realwrite("\n"))
             except Exception:
                 pass  # Okay if fails: can be python.exe from console
             try:
                 handle = win32console.GetStdHandle(
                     win32console.STD_OUTPUT_HANDLE)
                 handle.WriteConsole("\n" + text)
                 ConsoleWriter.handle = handle
                 ConsoleWriter.realwrite = handle.WriteConsole
             except Exception:  # Fails if GUI program: make new console
                 try:
                     win32console.FreeConsole()
                 except Exception:
                     pass
                 try:
                     win32console.AllocConsole()
                     handle = open("CONOUT$", "w")
                     argv = [util.longpath(sys.argv[0])] + sys.argv[1:]
                     handle.write(" ".join(argv) + "\n\n" + text)
                     handle.flush()
                     ConsoleWriter.handle = handle
                     ConsoleWriter.realwrite = handle.write
                     sys.stdin = open("CONIN$", "r")
                     exitfunc = lambda s: (handle.write(s), handle.flush(),
                                           raw_input())
                     atexit.register(exitfunc, "\nPress ENTER to exit.")
                 except Exception:
                     try:
                         win32console.FreeConsole()
                     except Exception:
                         pass
                     ConsoleWriter.realwrite = self.stream.write
             ConsoleWriter.is_loaded = True
         else:
             try:
                 self.realwrite(text)
                 self.flush()
             except Exception:
                 self.stream.write(text)
     else:
         self.stream.write(text)
Пример #4
0
 def write(self, text):
     """
     Prints text to console window. GUI application will need to attach to
     the calling console, or launch a new console if not available.
     """
     global window
     if not window and win32console:
         if not ConsoleWriter.is_loaded and not ConsoleWriter.handle:
             try:
                 win32console.AttachConsole(-1) # pythonw.exe from console
                 atexit.register(lambda: ConsoleWriter.realwrite("\n"))
             except Exception:
                 pass # Okay if fails: can be python.exe from console
             try:
                 handle = win32console.GetStdHandle(
                                       win32console.STD_OUTPUT_HANDLE)
                 handle.WriteConsole("\n" + text)
                 ConsoleWriter.handle = handle
                 ConsoleWriter.realwrite = handle.WriteConsole
             except Exception: # Fails if GUI program: make new console
                 try: win32console.FreeConsole()
                 except Exception: pass
                 try:
                     win32console.AllocConsole()
                     handle = open("CONOUT$", "w")
                     argv = [util.longpath(sys.argv[0])] + sys.argv[1:]
                     handle.write(" ".join(argv) + "\n\n" + text)
                     handle.flush()
                     ConsoleWriter.handle = handle
                     ConsoleWriter.realwrite = handle.write
                     sys.stdin = open("CONIN$", "r")
                     exitfunc = lambda s: (handle.write(s), handle.flush(),
                                           raw_input())
                     atexit.register(exitfunc, "\nPress ENTER to exit.")
                 except Exception:
                     try: win32console.FreeConsole()
                     except Exception: pass
                     ConsoleWriter.realwrite = self.stream.write
             ConsoleWriter.is_loaded = True
         else:
             try:
                 self.realwrite(text)
                 self.flush()
             except Exception:
                 self.stream.write(text)
     else:
         self.stream.write(text)