def _list_installed_packages(self, message): """ Called when a list of installed packages is received @param host : host @param pkg_type : type of package """ print("Get new installed packages list") self.log.debug("Get new installed packages list") self.sema_installed.acquire() self.log.debug("*** sema acquired") self.log.debug("*** msg = %s" % message) # process message host = message.data["host"] self._installed_packages[host] = {} pkg_mgr = PackageManager() idx = 0 loop_again = True self.log.debug("*** before while") while loop_again: try: self.log.debug("*** in while : idx=%s" % idx) pkg_type = message.data["type" + str(idx)] if message.data["enabled" + str(idx)].lower() == "yes": enabled = True else: enabled = False data = { "fullname": message.data["fullname" + str(idx)], "id": message.data["id" + str(idx)], "version": message.data["version" + str(idx)], "type": message.data["type" + str(idx)], #"source" : message.data["source"+str(idx)], "enabled": enabled } self.log.debug("*** call get_available_updates(%s, %s, %s)" % (data["type"], data["id"], data["version"])) updates = pkg_mgr.get_available_updates( data["type"], data["id"], data["version"]) self.log.debug("*** after get_available_updates") data["updates"] = updates if self._installed_packages[host].has_key(pkg_type) == False: self._installed_packages[host][pkg_type] = [] self._installed_packages[host][pkg_type].append(data) self.log.debug("*** before idx += 1") idx += 1 except KeyError: self.log.debug("*** except keyerror") loop_again = False except: self.log.debug("*** except global") self.log.error( "Error while creating list of installed packages : %s" % traceback.format_exc()) loop_again = False self.log.debug("*** before release") self.sema_installed.release() self.log.debug("*** sema released")
def _list_installed_packages(self, message): """ Called when a list of installed packages is received @param host : host @param pkg_type : type of package """ print("Get new installed packages list") self.log.debug("Get new installed packages list") self.sema_installed.acquire() self.log.debug("*** sema acquired") self.log.debug("*** msg = %s" % message) # process message host = message.data["host"] self._installed_packages[host] = {} pkg_mgr = PackageManager() idx = 0 loop_again = True self.log.debug("*** before while") while loop_again: try: self.log.debug("*** in while : idx=%s" % idx) pkg_type = message.data["type"+str(idx)] if message.data["enabled"+str(idx)].lower() == "yes": enabled = True else: enabled = False data = {"fullname" : message.data["fullname"+str(idx)], "id" : message.data["id"+str(idx)], "version" : message.data["version"+str(idx)], "type" : message.data["type"+str(idx)], #"source" : message.data["source"+str(idx)], "enabled" : enabled} self.log.debug("*** call get_available_updates(%s, %s, %s)" % (data["type"], data["id"], data["version"])) updates = pkg_mgr.get_available_updates(data["type"], data["id"], data["version"]) self.log.debug("*** after get_available_updates") data["updates"] = updates if self._installed_packages[host].has_key(pkg_type) == False: self._installed_packages[host][pkg_type] = [] self._installed_packages[host][pkg_type].append(data) self.log.debug("*** before idx += 1") idx += 1 except KeyError: self.log.debug("*** except keyerror") loop_again = False except: self.log.debug("*** except global") self.log.error("Error while creating list of installed packages : %s" % traceback.format_exc()) loop_again = False self.log.debug("*** before release") self.sema_installed.release() self.log.debug("*** sema released")
def main(): mgr = PackageManager() # Options management usage = "usage: %prog [options] <plugin name>" parser = OptionParser(usage = usage) parser.add_option("-c", "--create", action = "store_true", dest = "action_create", default = False, help = "Create a new package") parser.add_option("-f", "--force", action = "store_true", dest = "force", default = False, help = "Script won't ask user to continue or not") #parser.add_option("-i", "--install", # action = "store_true", # dest = "action_install", # default = False, # help = "Install a package (<package> [version])") parser.add_option("-u", "--update", action = "store_true", dest = "action_update", default = False, help = "Update packages list") parser.add_option("-l", "--list", action = "store_true", dest = "action_list", default = False, help = "Display cache's package list") #parser.add_option("-s", "--show", # action = "store_true", # dest = "action_show", # default = False, # help = "Display cache's package list") parser.add_option("-t", "--type", action = "store", dest = "package_type", help = "Package type : %s" % PACKAGE_TYPES) parser.add_option("-o", "--output-dir", action = "store", dest = "output_dir", help = "Directory where you want to create packages") parser.add_option("-n", "--nightly", action = "store_true", dest = "action_nightly", default = False, help = "Change the version in json file for nightly build") parser.add_option("-j", "--to-json", action = "store_true", dest = "action_json", default = False, help = "Convert the xml to json (temporary option for 0.2.0 development)") parser.add_option("-V", "--version", action="store_true", dest="display_version", default=False, help="Display Domogik version.") (options, args) = parser.parse_args() if options.display_version: __import__("domogik") global_release = sys.modules["domogik"].__version__ print global_release return # check args if (options.action_update == False \ and options.action_list == False )\ and len(args) < 1: parser.print_help() exit() # package creation if options.action_create == True: # check package type if options.package_type not in PACKAGE_TYPES: print("Error : : type must be in this list : %s" % PACKAGE_TYPES) exit() # plugin if options.package_type == "plugin": mgr._create_package_for_plugin(args[0], options.output_dir, options.force) # external if options.package_type == "external": mgr._create_package_for_external(args[0], options.output_dir, options.force) # package installation #if options.action_install == True: # if len(args) == 1: # mgr.install_package(args[0]) # if len(args) == 2: # mgr.install_package(args[0], args[1]) # packages list update if options.action_update == True: mgr.update_cache() # list packages in cache if options.action_list == True: mgr.list_packages() # show packages in cache #if options.action_show == True: # if len(args) == 1: # mgr.show_packages(args[0]) # if len(args) == 2: # mgr.show_packages(args[0], args[1]) if options.action_json == True: if options.package_type not in PACKAGE_TYPES: print("Error : : type must be in this list : %s" % PACKAGE_TYPES) exit() pkg_xml = PackageXml(args[0], pkg_type = options.package_type) print (pkg_xml.get_json()) if options.action_nightly == True: set_nightly_version(args[0])