def install_dependency(self, dependencyName, version, url, installDirectoryRelPath): savePath = utility.download_file(url, self.download_directory) utility.clear_directory_contents(self.extraction_directory) utility.extract_file(savePath, self.extraction_directory) os.remove(savePath) if self.installedDependencies.is_installed(dependencyName): self.remove_dependency(dependencyName) # not sure wether to add this or not (can cause serious impact) #if os.path.exists(installDirectory): # utility.log("installation directory {i} for dependency {d} already exist, overwriting it...".format(i=installDirectory,d=dependencyName)) # shutil.rmtree(installDirectory) installDirectory = utility.joinPaths(self.dependencies_directory, installDirectoryRelPath) utility.ensure_directory(installDirectory) # if the archive top level contains only one directory,copy its contents(not the directory itself) tempDirContents = [name for name in os.listdir(self.extraction_directory)] if len(tempDirContents) == 1 and os.path.isdir(utility.joinPaths(self.extraction_directory, tempDirContents[0])): dirPath = utility.joinPaths(self.extraction_directory, tempDirContents[0]) utility.move_directory_contents(dirPath, installDirectory) os.rmdir(dirPath) else: utility.move_directory_contents(self.extraction_directory, installDirectory) self.installedDependencies.add_dependency(dependencyName, version, installDirectoryRelPath) return True
def sync_dependencies(requiredDeps, installedDependencies, registryClient, repositoryClient, dependencyManager, flags): """synchronizing installed dependencies with requiredDeps, include installing,updating,downgrading and removing dependencies, in accordance to flags, Args: requiredDeps: array containing required dependencies for the project, in the format [{depName:version},{depName2,version}] installedDependencies: currently installed dependencies registryClient: client used for requesting a package details from the registry repositoryClient: client used for checking for a package repository url DependencyManager: responsible for dependency installation (or remove) flags: operations to be performed (can be update, install, downgrade, remove or any combintation of them) """ utility.log("synchronizing dependencies") utility.ensure_directory(DEPSINSTALL_DIR_PATH) required_dependencies_names = requiredDeps.get_dependencies_names() for depName in required_dependencies_names: utility.log("Processing {d}".format(d=depName), 1) # get current installed version (or set version to 0.0 for new dependencies) if installedDependencies.is_installed(depName): installedVersion = installedDependencies.get_installed_version(depName) else: installedVersion = str(StrictVersion('0.0')) # get and normalize required version requiredVersion = requiredDeps.get_dependency_version(depName) requiredVersion = str(StrictVersion(requiredVersion)) if StrictVersion(requiredVersion) == StrictVersion(installedVersion): utility.log("version {v} already installed".format(v=installedVersion)) elif StrictVersion(requiredVersion) < StrictVersion(installedVersion): if flags.downgrade: if install_dependency(depName, requiredVersion, dependencyManager, registryClient, repositoryClient): utility.log("{p} version {v} installed successfuly".format(p=depName, v=requiredVersion)) else: utility.log("{p} installation failed".format(p=depName)) else: utility.log("Required version {v1} < Installed version {v2}, No action taken (downgrade flag is not set)".format(v1=requiredVersion, v2=installedVersion)) else: if (flags.update and StrictVersion(installedVersion) > StrictVersion('0.0')) or (flags.install and StrictVersion(installedVersion) == StrictVersion('0.0')): if install_dependency(depName, requiredVersion, dependencyManager, registryClient, repositoryClient): utility.log("{p} version {v} installed successfuly".format(p=depName, v=requiredVersion)) else: utility.log("{p} installation failed".format(p=depName)) else: utility.log("Required version {v1} > Installed version {v2}, No action taken (update flag is not set)".format(v1=requiredVersion, v2=installedVersion)) # unident log messages utility.log("", -1) dependenciesToRemove = [item for item, version in installedDependencies.get_dependencies_list().items() if item not in required_dependencies_names] if dependenciesToRemove: utility.log("Installed dependencies that are not needed anymore : " + ",".join(dependenciesToRemove)) if not flags.remove: utility.log("ommiting uneeded dependencies (remove flag is not set)") else: for dependencyName in dependenciesToRemove: utility.log("removing {d}".format(d=dependencyName)) dependencyManager.remove_dependency(dependencyName) generate_environment(installedDependencies.get_dependencies_list(), registryClient, os.path.basename(DEPSINSTALL_DIR_PATH), GENERATED_ENVIRONMENT_PATH) utility.log("synchronization operation finished")
def __init__(self): utility.ensure_directory(SETTINGS_DIR_PATH) utility.ensure_file_directory(SETTINGS_FILE_PATH) settings = ConfigParser.RawConfigParser() if os.path.exists(SETTINGS_FILE_PATH): settings.read(SETTINGS_FILE_PATH) self.settings = settings if not self.settings.has_section(GENERAL_SECTION): self.settings.add_section(GENERAL_SECTION)
def __init__(self, installed_dependencies, base_directory): assert (isinstance(installed_dependencies, InstalledDependencies)) assert (base_directory and os.path.isdir(base_directory)) self.dependencies_directory = base_directory self.download_directory = utility.joinPaths(base_directory, TMPDOWNLOAD_DIR_NAME) self.extraction_directory = utility.joinPaths(self.download_directory, TMPEXTRACTION_DIR_NAME) utility.remove_file_or_dir(self.extraction_directory) utility.remove_file_or_dir(self.download_directory) utility.ensure_directory(self.download_directory) utility.ensure_directory(self.extraction_directory) self.installedDependencies = installed_dependencies
def cmd_sync(args): """cmd_sync validate and prepare synchronization operation environment""" flags = Flags(install=not args.without_install, update=not args.without_update, downgrade=not args.without_downgrade, remove=not args.without_remove) utility.ensure_directory(DEPSINSTALL_DIR_PATH) # load currently installed dependencies installedDeps = InstalledDependencies(load_installed_deps_file()) # make sure all dependencies are installed check_integrity(installedDeps, DEPSINSTALL_DIR_PATH) dependencyManager = DependencyManager(installedDeps, DEPSINSTALL_DIR_PATH) registryClient = get_registry_client() if not registryClient: print "registry server is not set, please set it before running ppm" return settings = Settings() if settings.get_current_project(): project_name = settings.get_current_project() try: jsonData = registryClient.get_project_details(project_name) except Exception as e: print "Error occured while retrieving project {p} details from registry server: {e}".format(p=project_name, e=str(e)) return elif os.path.exists(REQDEPS_FILE_PATH): try: jsonData = utility.load_json_file(REQDEPS_FILE_PATH) except Exception as e: print "Error occured while reading {f}: {e}".format(f=os.path.basename(REQDEPS_FILE_PATH), e=str(e)) return else: print "unable to fetch dependencies, you have to set a project or create a {d} file".format(d=os.path.basename(REQDEPS_FILE_PATH)) return requiredDeps = RequiredDependencies(jsonData.get('devdependencies',{})) repositoryClient = get_repository_client() # synchronizing dependencies sync_dependencies(requiredDeps, installedDeps, registryClient, repositoryClient, dependencyManager, flags) # save newly installed packages as current dependencies save_installed_deps(installedDeps.get_data())
def cmd_download(args): """ downloading one or more packages without monitoring them""" downloadDirectory = utility.joinPaths(os.getcwd(), args.directory) packages = [('@' in p and p.split('@')) or [p,"latest"] for p in args.packages] utility.ensure_directory(downloadDirectory) registryClient = get_registry_client() if not registryClient: raise Exception("registry server is not set, please set it using set-registry-server command") repositoryClient = get_repository_client() for name, version in packages: try: package_handler = registryClient.get_package_details(name) except Exception as e: utility.log(str(e)) continue if version == 'latest': version = get_latest_version(package_handler.get_package_versions()) if version == '0.0': utility.log("Package {p} is not in the ppm registry".format(p=name)) continue else: version = str(StrictVersion(version)) if not package_handler.check_version_existence(version): utility.log("Package {p} is not in the ppm registry".format(p=name)) continue url = package_handler.get_package_url(version) # check for repository url if repositoryClient: repository_url = repositoryClient.get_package_repository_url(url) if repository_url: url = repository_url utility.download_file(url, downloadDirectory)