Esempio n. 1
0
    def start(self):
        """Do the rest of the setup before turning control over to the reactor"""

        self._setup_environment()
        self._load_settings()
        self._load_data()
        self._create_applications()

        #in case this was the first run:
        self.bbApp.settings.fileName = os.path.join(
            Globals.USER_DATA_DIR, BitBlinder.BitBlinderSettings.defaultFile)
        GlobalEvents.throw_event("settings_changed")

        #must be done after settings are loaded
        self._start_psyco()

        #check for updates for the program:
        Updater.get().start()

        #start the bank
        bankStartupDeferred = self.bankApp.start()
        bankStartupDeferred.addCallback(self._on_bank_ready)
        bankStartupDeferred.addErrback(log_ex, "Bank failed to start!")

        #the rest of the startup code needs to run after the reactor has started:
        Scheduler.schedule_once(0.0, self._on_reactor_started)
Esempio n. 2
0
  def start(self):
    """Do the rest of the setup before turning control over to the reactor"""
    
    self._setup_environment()
    self._load_settings()
    self._load_data()
    self._create_applications()
    
    #in case this was the first run:
    self.bbApp.settings.fileName = os.path.join(Globals.USER_DATA_DIR, BitBlinder.BitBlinderSettings.defaultFile)
    GlobalEvents.throw_event("settings_changed")
    
    #must be done after settings are loaded
    self._start_psyco()
 
    #check for updates for the program:
    Updater.get().start()
    
    #start the bank
    bankStartupDeferred = self.bankApp.start()
    bankStartupDeferred.addCallback(self._on_bank_ready)
    bankStartupDeferred.addErrback(log_ex, "Bank failed to start!")
    
    #the rest of the startup code needs to run after the reactor has started:
    Scheduler.schedule_once(0.0, self._on_reactor_started)
Esempio n. 3
0
 def __init__(self, bot):
     self.bot = bot
     self.global_entry = BaseContext()
     self.updater = Updater(bot)
     self.updater.set_callback(self.dispatch_update)
     self.workers = list()
     self.workers_lock = Lock()
Esempio n. 4
0
 def update_check(self, widget=None, event=None):
   def success_cb(data, httpDownloadInstance):
     if not Updater.get().update_request_done(data, httpDownloadInstance):
       self.show_msgbox("You are using the latest available packaged version.")
     else:
       self.show_msgbox("BitBlinder is downloading a new version.  It will prompt you when the update is ready.")
   def failure_cb(failure, httpDownloadInstance):
     log_ex(failure, "Failed to manually check for update")
     self.show_msgbox("A server is temporarily offline; check back later.")
   Updater.get().check_for_updates(success_cb=success_cb, failure_cb=failure_cb)
Esempio n. 5
0
    def cleanup(self):
        """Make sure the reactor, threads, etc have been stopped.  Also removes
    the file that indicates we shutdown cleanly."""

        #shutdown Twisted
        if ProgramState.USE_GTK:
            Globals.reactor.stop()
            Globals.reactor.runUntilCurrent()

        #ensure that all threads have closed:
        remainingThreads = threading.enumerate()
        for thread in remainingThreads:
            if threading._MainThread != type(thread):
                log_msg(
                    "Thread has not finished by the end of the program: %s" %
                    (thread), 1)

        #start the update if necessary:
        if Updater.get().APPLY_UPDATE:
            ClientUtil.apply_update()

        #NOTE:  we intentionally leave the log files open so that errors can get written to them...
        log_msg("Thanks for using BitBlinder", 2)
        ErrorReporting.destroy_marker_file()

        #NOTE:  this is here so that threads can finish properly.  I was getting errors from leftover threads without it.
        #However, I'm pretty sure that it was just from the IDE
        time.sleep(0.2)
Esempio n. 6
0
  def cleanup(self):
    """Make sure the reactor, threads, etc have been stopped.  Also removes
    the file that indicates we shutdown cleanly."""
    
    #shutdown Twisted
    if ProgramState.USE_GTK:
      Globals.reactor.stop()
      Globals.reactor.runUntilCurrent()
      
    #ensure that all threads have closed:
    remainingThreads = threading.enumerate()
    for thread in remainingThreads:
      if threading._MainThread != type(thread):
        log_msg("Thread has not finished by the end of the program: %s" % (thread), 1)

    #start the update if necessary:
    if Updater.get().APPLY_UPDATE:
      ClientUtil.apply_update()
      
    #NOTE:  we intentionally leave the log files open so that errors can get written to them...
    log_msg("Thanks for using BitBlinder", 2)
    ErrorReporting.destroy_marker_file()
    
    #NOTE:  this is here so that threads can finish properly.  I was getting errors from leftover threads without it.
    #However, I'm pretty sure that it was just from the IDE
    time.sleep(0.2)
Esempio n. 7
0
 def success_cb(data, httpDownloadInstance):
     if not Updater.get().update_request_done(data,
                                              httpDownloadInstance):
         self.show_msgbox(
             "You are using the latest available packaged version.")
     else:
         self.show_msgbox(
             "BitBlinder is downloading a new version.  It will prompt you when the update is ready."
         )
Esempio n. 8
0
    def update_check(self, widget=None, event=None):
        def success_cb(data, httpDownloadInstance):
            if not Updater.get().update_request_done(data,
                                                     httpDownloadInstance):
                self.show_msgbox(
                    "You are using the latest available packaged version.")
            else:
                self.show_msgbox(
                    "BitBlinder is downloading a new version.  It will prompt you when the update is ready."
                )

        def failure_cb(failure, httpDownloadInstance):
            log_ex(failure, "Failed to manually check for update")
            self.show_msgbox(
                "A server is temporarily offline; check back later.")

        Updater.get().check_for_updates(success_cb=success_cb,
                                        failure_cb=failure_cb)
Esempio n. 9
0
class BotHive:
    def __init__(self, bot):
        self.bot = bot
        self.global_entry = BaseContext()
        self.updater = Updater(bot)
        self.updater.set_callback(self.dispatch_update)
        self.workers = list()
        self.workers_lock = Lock()

    def _new_worker(self):
        w = WorkerBee(self.bot, self.global_entry)
        self.workers.append(w)

    def dispatch_update(self, update):
        # todo replace to some more complicated worker management
        self.workers_lock.acquire()
        if not self.workers:
            self._new_worker()
        self.workers_lock.release()
        self.workers[0].dispatch_update(update)

    def start(self):
        self.updater.start()
        for w in self.workers:
            w.start()

    def monitor(self):
        import time
        while True:
            for w in self.workers:
                print(f'+ ==< {w.id} >==')
                for s in w.sessions:
                    print(f'| {s.id} >=< {[c.id for c in s.contexts]}')
                print('+ ==< {+} >==')
                print('\n\n')
            time.sleep(1)

    def idle(self):
        import time
        while True:
            time.sleep(1)
Esempio n. 10
0
def run(args):
    validation = InstallValidator.validate()
    if not validation["valid"] or "--validate" in args:
        components = validation["components"]
        for component in components:
            if component == "python":
                if sys.version_info[0] < 3:
                    print("  %s\t= required version 3 or later" % (component) +
                          " (current version is %s.%s)" %
                          (sys.version_info[:2]))
                else:
                    print("  %s\t= installed" % (component) +
                          " (current version is %s.%s)" %
                          (sys.version_info[:2]))
            else:
                print("  %s\t= %s" %
                      (component, "installed"
                       if components[component] else "not installed"))
        return
    InstallValidator.update_updater()
    if "-v" in args or "--version" in args:
        print("OPUS %s" % VERSION)
        return
    for key in ["--help", "-h", "-?"]:
        if key in args:
            args.remove(key)
            OpusHelp.print_help(args)
            return
    debug = False
    for key in ["--debug", "-d"]:
        if key in args:
            args.remove(key)
            debug = True
            break
    for key in ["--update", "-u", "--force-update", "-fu"]:
        if key in args:
            args.remove(key)
            updater = Updater(VERSION, key in ["--force-update", "-fu"])
            updater.update()
            updater.ready_to_update()
            notice = False
            print("Checking for OPUS updates...")
            while not updater.finish():
                if not notice and updater.has_new_update():
                    print("Updating OPUS to v%s..." % (updater.get_version()))
                    notice = True
            if updater.is_failed():
                print(
                    "OPUS update is failed. Process will try again next time.")
            return
    projects = []
    files = os.listdir(".")
    for file_name in files:
        if is_project(file_name):
            projects.append(file_name)
    project = None
    if len(args) >= 2 and is_support(args[1]):
        project = args[1]
        args = args[2:]
    elif len(projects) == 1:
        project = projects[0]
        args = args[1:]
    elif len(projects) > 1:
        print("More than one project exists. " +
              "Please specified it like this...")
        print("  python %s <project file>" % (args[0]))
        return
    elif len(projects) == 0:
        print("No project found. Please specified the project file " +
              "or put it in the current location.")
        return
    elif len(args) >= 2:
        print("%s is not OPUS project file" % (args[1]))
        return
    updater = Updater(VERSION)
    if not debug:
        updater.update()
    print("Working with %s" % (project))
    if is_project(project):
        opus_project = OpusProject(project)
        opus_project.compile(args)
    else:
        # TODO (if needed)
        print("OPUS document compilation is not implemented yet.")
        print("Please contact the developer if you want to use this.")
        opus_doc = OpusDocument(project)
        opus_doc.compile(args)
    if not debug:
        start_time = time.time()
        timeout = False
        notice = False
        updater.ready_to_update()
        while not updater.finish():
            if not timeout and time.time() - start_time > 3:
                print("Please wait while OPUS checking for new update...")
                timeout = True
            if not notice and updater.has_new_update():
                print("Updating OPUS to v%s..." % (updater.get_version()))
                notice = True
        if updater.is_failed():
            print("OPUS update is failed. Process will try again next time.")
Esempio n. 11
0
 def success_cb(data, httpDownloadInstance):
   if not Updater.get().update_request_done(data, httpDownloadInstance):
     self.show_msgbox("You are using the latest available packaged version.")
   else:
     self.show_msgbox("BitBlinder is downloading a new version.  It will prompt you when the update is ready.")