Esempio n. 1
0
 def setup(self):
     library = parse_library_files(self.file_layout)
     if self.pw_database:
         pw_database = self.pw_database
     elif not self.has_pw_file:
         import engage.utils.pw_repository as pw_repository
         pw_database = pw_repository.PasswordRepository("")
     else:
         pw_database = None # setup_context() will read the db
     import install_context
     install_context.setup_context(self.file_layout,
                                   False, library, pw_database)
     with open(self.install_script_file, "rb") as f:
         resource_list_json = json.load(f)
     rlist = [r for r in ifilter(lambda res: res["id"]==self.resource_id,
                                 resource_list_json)]
     if len(rlist)==0:
         raise Exception("Resource %s not found" % self.resource_id)
     if len(rlist)>1:
         raise Exception("Multiple instances of resource %s!" %
                         self.resource_id)
     resource = parse_resource_from_json(rlist[0])
     entry = library.get_entry(resource)
     if entry==None:
         raise Exception("Unable to find library entry for %s, of resource type %s %s" % (resource.id, resource.key["name"], resource.key["version"]))
     resource_manager_class = entry.get_manager_class()
     if self.options.dry_run:
         mgr = resource_manager_class(resource, dry_run=True)
     else:
         mgr = resource_manager_class(resource)
     mgr.install_context = install_context
     return (mgr, entry.get_package())
Esempio n. 2
0
def get_mgrs_and_pkgs(file_layout, deployment_home, options,
                      resource_file=None):
    """Perform common initialization operations, returning
    a list of (mgr, pkg) pairs sorted in dependency order.
    """
    import library
    import install_plan
    l = library.parse_library_files(file_layout)
    import engage.engine.password
    pw_database = engage.engine.password.get_password_db(file_layout, options)
    import install_context
    install_context.setup_context(file_layout, options.subproc, l, pw_database)

    if not resource_file:
        resource_file = file_layout.get_installed_resources_file(deployment_home)

    def get_manager_and_pkg(resource):
        if resource.package!=None:
            # new style packags are on the resource
            package = resource.package
            resource_manager_class = resource.get_resource_manager_class()
        else:
            entry = l.get_entry(resource)
            assert entry, "Unable to find entry for resource %s in library file %s" % (resource.id, file_layout.get_software_library_file())
            resource_manager_class = entry.get_manager_class()
            package = entry.get_package()
        mgr = resource_manager_class(resource)
        import install_context
        mgr.install_context = install_context
        return (mgr, package)
        
    with open(resource_file, "rb") as f:
        resource_list_json = json.load(f)
    rlist =  [parse_resource_from_json(resource_json) for
              resource_json in resource_list_json]
    return [get_manager_and_pkg(r) for r in install_plan.create_install_plan(rlist)]