Example #1
0
    def __init__(self, inst_dir, cb):
        self.dir = inst_dir
        self.cb = cb
        self.inst = SwInst()
        self.fs = FsNotifyChange()
        self.running = False
        self.cur_fn = None

        self.rescan_files()
        self.fs_observe()
Example #2
0
class GUI:
    def __init__(self):
        self.lock = e32.Ao_lock()
        self.main_title = u"FsChangeTest"
        self.old_title = appuifw.app.title

        app_path = os.path.split(appuifw.app.full_name())[0]
        self.app_drive = app_path[:2]

        main_menu = [
            (u"Exit", self.abort)
            ]

        appuifw.app.title = self.main_title
        appuifw.app.menu = main_menu
        appuifw.app.exit_key_handler = self.abort

        # Yes, it seems that a full pathname is required, including
        # the drive letter. So unfortunately a single invocation
        # cannot request observing the same path on multiple different
        # drives.
        self.dir = u"e:\\images"
        
        self.fs = FsNotifyChange()
        self.fs_observe()

    def fs_observe(self):
        self.fs.notify_change(1, self._dir_changed, self.dir)
        
    def _dir_changed(self, error):
        if error == 0:
            print "got change event"
            self.fs_observe()
        else:
            print "got error %d" % error

    def abort(self):
        self.lock.signal()

    def loop(self):
        self.lock.wait()

    def close(self):
        self.fs.close()
        appuifw.app.menu = []
        appuifw.app.exit_key_handler = None
        appuifw.app.title = self.old_title
Example #3
0
    def __init__(self, inst_dir, cb):
        self.dir = inst_dir
        self.cb = cb
        self.inst = SwInst()
        self.fs = FsNotifyChange()
        self.running = False
        self.cur_fn = None

        self.rescan_files()
        self.fs_observe()
Example #4
0
    def __init__(self):
        self.lock = e32.Ao_lock()
        self.main_title = u"FsChangeTest"
        self.old_title = appuifw.app.title

        app_path = os.path.split(appuifw.app.full_name())[0]
        self.app_drive = app_path[:2]

        main_menu = [
            (u"Exit", self.abort)
            ]

        appuifw.app.title = self.main_title
        appuifw.app.menu = main_menu
        appuifw.app.exit_key_handler = self.abort

        # Yes, it seems that a full pathname is required, including
        # the drive letter. So unfortunately a single invocation
        # cannot request observing the same path on multiple different
        # drives.
        self.dir = u"e:\\images"
        
        self.fs = FsNotifyChange()
        self.fs_observe()
Example #5
0
class AutoInstaller:
    def __init__(self, inst_dir, cb):
        self.dir = inst_dir
        self.cb = cb
        self.inst = SwInst()
        self.fs = FsNotifyChange()
        self.running = False
        self.cur_fn = None

        self.rescan_files()
        self.fs_observe()

    def send_ev(self, ev_type, msg):
        print msg
        self.cb(ev_type)

    def fs_observe(self):
        self.fs.notify_change(1, self._dir_changed, self.dir)

    def _dir_changed(self, error):
        if error == 0:
            self.send_ev("dir_change", "change(s) in directory")
            self.rescan_files()
            self.fs_observe()
            if (not self.cur_fn):
                self.install_next()
        else:
            self.send_ev("fatal_error", "fs notify error %d" % error)

    def rescan_files(self):
        self.files = scan_files_r(self.dir)

    def _sw_installed(self, error):
        fn = self.cur_fn
        self.cur_fn = None
        try:
            self.files.remove(fn)
        except ValueError:
            pass
        if error == 0:
            self.send_ev("inst_ok", "install OK: %s" % fn)
            self.delete_file(fn)
        else:
            self.send_ev("inst_fail",
                         "failed to install %s (error %d)" % (fn, error))
        self.install_next()

    def delete_file(self, fn):
        try:
            os.unlink(to_str(fn))
            self.send_ev("del_ok", u"deleted %s" % fn)
        except:
            self.send_ev("del_fail", u"failed to delete %s" % fn)

    def install_file(self, fn):
        self.send_ev("inst_start", u"installing %s" % fn)
        try:
            self.inst.install(fn,
                              self._sw_installed,
                              capabilities=opt_capabilities,
                              untrusted=opt_untrusted)
            self.cur_fn = fn
        except:
            self.send_ev("inst_fail", "failed to install %s" % fn)

    def install_next(self):
        if self.running and len(self.files) > 0:
            self.install_file(self.files[0])
        else:
            self.send_ev("no_more", "nothing more to install")

    def start(self):
        if not self.running:
            self.send_ev("started", "auto-installing from: %s" % self.dir)
            self.running = True
            self.install_next()

    def stop(self):
        if self.running:
            self.inst.cancel()
            self.running = False
            self.send_ev("stopped", "auto-installing stopped")

    def close(self):
        self.stop()
        self.fs.close()
        self.inst.close()
Example #6
0
class AutoInstaller:
    def __init__(self, inst_dir, cb):
        self.dir = inst_dir
        self.cb = cb
        self.inst = SwInst()
        self.fs = FsNotifyChange()
        self.running = False
        self.cur_fn = None

        self.rescan_files()
        self.fs_observe()

    def send_ev(self, ev_type, msg):
        print msg
        self.cb(ev_type)

    def fs_observe(self):
        self.fs.notify_change(1, self._dir_changed, self.dir)
        
    def _dir_changed(self, error):
        if error == 0:
            self.send_ev("dir_change", "change(s) in directory")
            self.rescan_files()
            self.fs_observe()
            if (not self.cur_fn):
                self.install_next()
        else:
            self.send_ev("fatal_error", "fs notify error %d" % error)

    def rescan_files(self):
        self.files = scan_files_r(self.dir)

    def _sw_installed(self, error):
        fn = self.cur_fn
        self.cur_fn = None
        try:
            self.files.remove(fn)
        except ValueError:
            pass
        if error == 0:
            self.send_ev("inst_ok", "install OK: %s" % fn)
            self.delete_file(fn)
        else:
            self.send_ev("inst_fail", "failed to install %s (error %d)" % (fn, error))
        self.install_next()

    def delete_file(self, fn):
        try:
            os.unlink(to_str(fn))
            self.send_ev("del_ok", u"deleted %s" % fn)
        except:
            self.send_ev("del_fail", u"failed to delete %s" % fn)
            
    def install_file(self, fn):
        self.send_ev("inst_start", u"installing %s" % fn)
        try:
            self.inst.install(fn, self._sw_installed, capabilities = opt_capabilities, untrusted = opt_untrusted)
            self.cur_fn = fn
        except:
            self.send_ev("inst_fail", "failed to install %s" % fn)

    def install_next(self):
        if self.running and len(self.files) > 0:
            self.install_file(self.files[0])
        else:
            self.send_ev("no_more", "nothing more to install")

    def start(self):
        if not self.running:
            self.send_ev("started", "auto-installing from: %s" % self.dir)
            self.running = True
            self.install_next()

    def stop(self):
        if self.running:
            self.inst.cancel()
            self.running = False
            self.send_ev("stopped", "auto-installing stopped")

    def close(self):
        self.stop()
        self.fs.close()
        self.inst.close()