Esempio n. 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()
Esempio n. 2
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()
Esempio n. 3
0
import e32
from pyswinst import SwInst

myLock = e32.Ao_lock()


def cb(*args):
    print repr(args)
    myLock.signal()


inst = SwInst()
try:
    inst.install(u"e:\\software\\screenshot_s60_3rd_2.80.sisx", cb)
    myLock.wait()
finally:
    inst.close()

print "all done"
Esempio n. 4
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()
import e32
from pyswinst import SwInst

myLock = e32.Ao_lock()

def cb(*args):
    print repr(args)
    myLock.signal()

inst = SwInst()
try:
    inst.install(u"e:\\software\\screenshot_s60_3rd_2.80.sisx", cb)
    myLock.wait()
finally:
    inst.close()

print "all done"
Esempio n. 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()