Example #1
0
File: main.py Project: shaurz/devo
    def Startup(self, args):
        from dialogs import dialogs
        try:
            import async_wx
            from app_instance import AppListener, get_app_instance
            from fileutil import get_user_config_dir, mkpath
            from log_file import get_log_file

            async_wx.set_wx_scheduler()

            config_dir = get_user_config_dir("devo")
            try:
                mkpath(config_dir)
            except OSError as e:
                message = "Failed to create Devo configuration directory:\n\n" + str(e)
                dialogs.error(None, message, "Initialization Error")
                return False

            if not args.new_instance:
                instance = get_app_instance("devo")
                if instance:
                    try:
                        if instance.call("process_args", args.raw_args, os.getcwd()):
                            return False
                    except Exception:
                        pass

                self.listener = AppListener("devo", DevoAppHandler(self))

            if hasattr(sys, "frozen"):
                log_filename = os.path.join(config_dir, "errors.log")
                self.log_file = get_log_file(log_filename)
                sys.stdout, self.stdout = self.log_file, sys.stdout
                sys.stderr, self.stderr = self.log_file, sys.stderr

            from mainframe import MainFrame
            self.mainframe = MainFrame.__new__(MainFrame, args)
            self.mainframe.__init__(args)
            self.SetTopWindow(self.mainframe)

            self.Bind(wx.EVT_END_SESSION, self.OnEndSession)

            return True

        except Exception:
            message = "Devo failed to initialize due to the following error:\n\n" + traceback.format_exc()
            if self.mainframe:
                try:
                    self.mainframe.Destroy()
                except Exception:
                    pass
            dialogs.error(None, message, "Initialization Error")
            return False
Example #2
0
 def do_write_file(path, text):
     mkpath(os.path.dirname(path))
     atomic_write_file(path, text)
Example #3
0
def write_settings(filename, settings):
    fileutil.mkpath(os.path.dirname(filename))
    data = json.dumps(settings, indent=2, sort_keys=True)
    fileutil.atomic_write_file(filename, data)