示例#1
0
    def loop_iteration(self, timeout=1):
        self._stack.append(None)
        try:
            if self.check_events():
                return
            self._prepare_pending()

            def dummy_cb():
                "Dummy callback function to force event if none are pending."
                self._anything_done = True
                logger.debug("Dummy timeout func called")
                return True

            self._anything_done = False
            tag = None
            logger.debug("Calling main_context_default().iteration()")
            while not self._anything_done:
                if not glib.main_context_default().pending() and not tag:
                    tag = glib.timeout_add(int(timeout * 1000), dummy_cb)
                glib.main_context_default().iteration(True)
            if tag:
                glib.source_remove(tag)
            logger.debug("..main_context_default().iteration() exited")
        finally:
            self._stack.pop()
        if self.exc_info:
            (exc_type, exc_value, ext_stack), self.exc_info = (self.exc_info,
                                                               None)
            raise exc_type, exc_value, ext_stack
示例#2
0
文件: glib.py 项目: DanyPlay/pyxmpp2
 def loop_iteration(self, timeout = 1):
     self._stack.append(None)
     try:
         if self.check_events():
             return
         self._prepare_pending()
         def dummy_cb():
             "Dummy callback function to force event if none are pending."
             self._anything_done = True
             logger.debug("Dummy timeout func called")
             return True
         self._anything_done = False
         tag = None
         logger.debug("Calling main_context_default().iteration()")
         while not self._anything_done:
             if not glib.main_context_default().pending() and not tag:
                 tag = glib.timeout_add(int(timeout * 1000), dummy_cb)
             glib.main_context_default().iteration(True)
         if tag:
             glib.source_remove(tag)
         logger.debug("..main_context_default().iteration() exited")
     finally:
         self._stack.pop()
     if self.exc_info:
         (exc_type, exc_value, ext_stack), self.exc_info = (self.exc_info,
                                                                     None)
         raise exc_type, exc_value, ext_stack
示例#3
0
def main():
    keylog_path = parse_args()

    if not isfile(keylog_path):
        with open(keylog_path, "w") as keylog_file:
            b = [
                u"pressed",
                u"keycode",
                u"keysym",
                u"symbol",
                u"repr",
                u"repeated",
                u"mods_mask"]
            print("%7s %7s %6s %16s %9s %8s %15s" % tuple(b))
            keylog_file = keylog_file.write('\t'.join(b) + u'\n')

    def callback(data):
        values = {}
        for k in dir(data):
            if k[0] == '_':
                continue
            values[k] = getattr(data, k)
            # print k, values[k]
        if not values[u"filtered"]:
            #values[u"mods_mask"] = bin(values[u"mods_mask"])[2:]
            values[u"pressed"] = int(values[u"pressed"])
            values[u"repeated"] = int(values[u"repeated"])
            if values[u"string"] == "'":
                values[u"string"] = '\'\\\'\''  # repr of ' with ' string, not " as usual to make all strings in one format
            else:
                values[u"string"] = repr(values[u"string"])
            values[u"symbol"] = values["symbol"].decode("utf-8")
            b = [str(values[k]) for k in [u"pressed", u"keycod", u"keysym", u"symbol", u"string", u"repeated", u"mods_mask"]]
            print("%7s %7s %6s %16s %9s %8s %15s" % tuple(b))
            with open(keylog_path, "a") as keylog_file:
                keylog_file.write('\t'.join(b) + u'\n')

    glib.threads_init()
    kl = InputListener(callback)
    try:
        # keep running only while the listener is alive
        kl.start()
        while kl.is_alive():
            glib.main_context_default().iteration()
    except KeyboardInterrupt:
        pass

    # check if the thread terminated unexpectedly
    if kl.is_alive():
        kl.stop()
        kl.join()
    elif kl.error:
        print("initialization error: {}".format(kl.error))
        if '__traceback__' in dir(kl.error):
            import traceback
            traceback.print_tb(kl.error.__traceback__)
        exit(1)
示例#4
0
 def __init__(self, term):
     base.InstallProgress.__init__(self)
     gobject.GObject.__init__(self)
     self.finished = False
     self.apt_status = -1
     self.time_last_update = time.time()
     self.term = term
     self.term.connect("child-exited", self.child_exited)
     self.env = ["VTE_PTY_KEEP_FD=%s" % self.writefd,
                 "DEBIAN_FRONTEND=gnome",
                 "APT_LISTCHANGES_FRONTEND=gtk"]
     self._context = glib.main_context_default()
示例#5
0
 def __init__(self, term):
     base.InstallProgress.__init__(self)
     gobject.GObject.__init__(self)
     self.finished = False
     self.apt_status = -1
     self.time_last_update = time.time()
     self.term = term
     self.term.connect("child-exited", self.child_exited)
     self.env = ["VTE_PTY_KEEP_FD=%s" % self.writefd,
                 "DEBIAN_FRONTEND=gnome",
                 "APT_LISTCHANGES_FRONTEND=gtk"]
     self._context = glib.main_context_default()
示例#6
0
 def _on_textview_event(self, textview, _event):
     if self._wrong_offset:
         return
     first_validate_idle = ct.c_uint.from_address(
         hash(textview)+self.first_validate_idle_offset)
     con = glib.main_context_default()
     while first_validate_idle.value != 0:
         if not con.pending():
             # No pending callbacks, and still not 0? We have the wrong offset
             self._wrong_offset = True
             print >> sys.stderr, 'Warning: wrong first_validate_idle offset'
             return
         con.iteration()
示例#7
0
 def __init__(self, useGtk=True):
     self._simtag = None
     self._reads = set()
     self._writes = set()
     self._sources = {}
     posixbase.PosixReactorBase.__init__(self)
     if useGtk:
         import gtk
         self.__pending = gtk.events_pending
         self.__iteration = gtk.main_iteration
         self.__crash = _our_mainquit
         self.__run = gtk.main
     else:
         self.context = glib.main_context_default()
         self.__pending = self.context.pending
         self.__iteration = self.context.iteration
         self.loop = glib.MainLoop()
         self.__crash = self.loop.quit
         self.__run = self.loop.run
示例#8
0
 def __init__(self, useGtk=True):
     self._simtag = None
     self._reads = set()
     self._writes = set()
     self._sources = {}
     posixbase.PosixReactorBase.__init__(self)
     if useGtk:
         import gtk
         self.__pending = gtk.events_pending
         self.__iteration = gtk.main_iteration
         self.__crash = _our_mainquit
         self.__run = gtk.main
     else:
         self.context = glib.main_context_default()
         self.__pending = self.context.pending
         self.__iteration = self.context.iteration
         self.loop = glib.MainLoop()
         self.__crash = self.loop.quit
         self.__run = self.loop.run
示例#9
0
 def __init__(self):
     old.FetchProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._continue = True
     self._context = glib.main_context_default()
示例#10
0
 def __init__(self):
     base.OpProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._context = glib.main_context_default()
示例#11
0
 def __init__(self):
     base.AcquireProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._continue = True
     self._context = glib.main_context_default()
    global active
    active -= 1
    return True

def run(t):
    if WITH_GUI:
        dia = AptProgressDialog(t)
        dia.run()
        dia.destroy()
    else:
        t.run()

if __name__ == "__main__":
    #logging.basicConfig(level=logging.DEBUG)

    context = glib.main_context_default()
    c = AptClient()
    for i in range(100):
        
        print "inst: 3dchess"
        t = c.install_packages(["3dchess"], exit_handler=exit_handler)
        run(t)
        active += 1

        print "inst: 2vcard"
        t = c.install_packages(["2vcard"], exit_handler=exit_handler)
        run(t)
        active += 1
        
        print "rm: 3dchess 2vcard"
        t = c.remove_packages(["3dchess","2vcard"], exit_handler=exit_handler)
示例#13
0
if __name__ == '__main__':

    def callback(data):
        values = {}
        for k in dir(data):
            if k[0] == '_': continue
            values[k] = getattr(data, k)
        print(values)

    glib.threads_init()
    kl = InputListener(callback)
    try:
        # keep running only while the listener is alive
        kl.start()
        while kl.is_alive():
            glib.main_context_default().iteration()
    except KeyboardInterrupt:
        pass

    # check if the thread terminated unexpectedly
    if kl.is_alive():
        kl.stop()
        kl.join()
    elif kl.error:
        print("initialization error: {}".format(kl.error))
        if '__traceback__' in dir(kl.error):
            import traceback
            traceback.print_tb(kl.error.__traceback__)
        exit(1)
示例#14
0
 def __init__(self):
     base.AcquireProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._continue = True
     self._context = glib.main_context_default()
示例#15
0
def update(db, cache, datadir=APP_INSTALL_PATH):
    " index the desktop files in $datadir/desktop/*.desktop "
    term_generator = xapian.TermGenerator()
    seen = set()
    context = glib.main_context_default()
    popcon_max = 0
    for desktopf in glob(datadir+"/desktop/*.desktop"):
        logging.debug("processing %s" % desktopf)
        # process events
        while context.pending():
            context.iteration()
        parser = DesktopConfigParser()
        doc = xapian.Document()
        term_generator.set_document(doc)
        try:
            parser.read(desktopf)
            # app name is the data
            name = parser.get_desktop("Name")
            if name in seen:
                logging.debug("duplicated name '%s' (%s)" % (name, desktopf))
            seen.add(name)
            doc.set_data(name)
            index_name(doc, name, term_generator)
            # check if we should ignore this file
            if parser.has_option_desktop("X-AppInstall-Ignore"):
                ignore = parser.get_desktop("X-AppInstall-Ignore")
                if ignore.strip().lower() == "true":
                    logging.debug(
                        "X-AppInstall-Ignore found for '%s'" % desktopf)
                    continue
            # package name
            pkgname = parser.get_desktop("X-AppInstall-Package")
            doc.add_term("AP"+pkgname)
            doc.add_value(XAPIAN_VALUE_PKGNAME, pkgname)
            doc.add_value(XAPIAN_VALUE_DESKTOP_FILE, desktopf)
            # pocket (main, restricted, ...)
            if parser.has_option_desktop("X-AppInstall-Section"):
                archive_section = parser.get_desktop("X-AppInstall-Section")
                doc.add_term("AS"+archive_section)
                doc.add_value(XAPIAN_VALUE_ARCHIVE_SECTION, archive_section)
            # section (mail, base, ..)
            if pkgname in cache and cache[pkgname].candidate:
                section = cache[pkgname].candidate.section
                doc.add_term("AE"+section)
            # channel (third party stuff)
            if parser.has_option_desktop("X-AppInstall-Channel"):
                archive_channel = parser.get_desktop("X-AppInstall-Channel")
                doc.add_term("AH"+archive_channel)
                doc.add_value(XAPIAN_VALUE_ARCHIVE_CHANNEL, archive_channel)
            # icon
            if parser.has_option_desktop("Icon"):
                icon = parser.get_desktop("Icon")
                doc.add_value(XAPIAN_VALUE_ICON, icon)
            # write out categories
            for cat in parser.get_desktop_categories():
                doc.add_term("AC"+cat.lower())
            # get type (to distinguish between apps and packages
            if parser.has_option_desktop("Type"):
                type = parser.get_desktop("Type")
                doc.add_term("AT"+type.lower())
            # check gettext domain
            if parser.has_option_desktop("X-Ubuntu-Gettext-Domain"):
                domain = parser.get_desktop("X-Ubuntu-Gettext-Domain")
                doc.add_value(XAPIAN_VALUE_GETTEXT_DOMAIN, domain)
            # architecture
            if parser.has_option_desktop("X-AppInstall-Architectures"):
                arches = parser.get_desktop("X-AppInstall-Architectures")
                doc.add_value(XAPIAN_VALUE_ARCHIVE_ARCH, arches)
            # popcon
            # FIXME: popularity not only based on popcon but also
            #        on archive section, third party app etc
            if parser.has_option_desktop("X-AppInstall-Popcon"):
                popcon = float(parser.get_desktop("X-AppInstall-Popcon"))
                # sort_by_value uses string compare, so we need to pad here
                doc.add_value(XAPIAN_VALUE_POPCON, 
                              xapian.sortable_serialise(popcon))
                popcon_max = max(popcon_max, popcon)

            # comment goes into the summary data if there is one,
            # other wise we try GenericName and if nothing else,
            # the summary of the package
            if parser.has_option_desktop("Comment"):
                s = parser.get_desktop("Comment")
                doc.add_value(XAPIAN_VALUE_SUMMARY, s)
            elif parser.has_option_desktop("GenericName"):
                s = parser.get_desktop("GenericName")
                if s != name:
                    doc.add_value(XAPIAN_VALUE_SUMMARY, s)
            elif pkgname in cache and cache[pkgname].candidate:
                s = cache[pkgname].candidate.summary
                doc.add_value(XAPIAN_VALUE_SUMMARY, s)

            # add packagename as meta-data too
            term_generator.index_text_without_positions(pkgname, WEIGHT_APT_PKGNAME)

            # now add search data from the desktop file
            for key in ["GenericName","Comment"]:
                if not parser.has_option_desktop(key):
                    continue
                s = parser.get_desktop(key)
                # we need the ascii_upper here for e.g. turkish locales, see
                # bug #581207
                w = globals()["WEIGHT_DESKTOP_" + ascii_upper(key.replace(" ", ""))]
                term_generator.index_text_without_positions(s, w)
            # add data from the apt cache
            if pkgname in cache and cache[pkgname].candidate:
                s = cache[pkgname].candidate.summary
                term_generator.index_text_without_positions(s, WEIGHT_APT_SUMMARY)
                s = cache[pkgname].candidate.description
                term_generator.index_text_without_positions(s, WEIGHT_APT_DESCRIPTION)
                for origin in cache[pkgname].candidate.origins:
                    doc.add_term("XOA"+origin.archive)
                    doc.add_term("XOC"+origin.component)
                    doc.add_term("XOL"+origin.label)
                    doc.add_term("XOO"+origin.origin)
                    doc.add_term("XOS"+origin.site)

            # add our keywords (with high priority)
            if parser.has_option_desktop("X-AppInstall-Keywords"):
                keywords = parser.get_desktop("X-AppInstall-Keywords")
                for s in keywords.split(";"):
                    if s:
                        term_generator.index_text_without_positions(s, WEIGHT_DESKTOP_KEYWORD)
                
            # FIXME: now do the same for the localizations in the
            #        desktop file
            # FIXME3: add X-AppInstall-Section
        except Exception, e:
            # Print a warning, no error (Debian Bug #568941)
            logging.warning("error processing: %s %s" % (desktopf, e))
            continue
        # now add it
        db.add_document(doc)
示例#16
0

if __name__ == '__main__':
    def callback(data):
        values = {}
        for k in dir(data):
            if k[0] == '_': continue
            values[k] = getattr(data, k)
        print(values)

    glib.threads_init()
    kl = InputListener(callback)
    try:
        # keep running only while the listener is alive
        kl.start()
        while kl.is_alive():
            glib.main_context_default().iteration()
    except KeyboardInterrupt:
        pass

    # check if the thread terminated unexpectedly
    if kl.is_alive():
        kl.stop()
        kl.join()
    elif kl.error:
        print("initialization error: {}".format(kl.error))
        if '__traceback__' in dir(kl.error):
            import traceback
            traceback.print_tb(kl.error.__traceback__)
        exit(1)
示例#17
0
 def __init__(self):
     old.FetchProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._continue = True
     self._context = glib.main_context_default()
示例#18
0
 def __init__(self):
     base.OpProgress.__init__(self)
     gobject.GObject.__init__(self)
     self._context = glib.main_context_default()