def _cleanup(self, package_name, version, platform, manifest_filename): try: depot_mf = os.path.join(self._depot_mf_path, manifest_filename) if os.path.exists(depot_mf): os.remove(depot_mf) depot_pkg = CommonUtils.generate_package_name(package_name, version, platform) depot_df = os.path.join(self._location, CommonConsts.SW_DEPOT_DATAFILES_DIR , depot_pkg) if os.path.exists(depot_df): shutil.rmtree(depot_df) except Exception as e: print "Exception while cleanup: ", e
def _deploy_package(self, package_name, version, platform, manifest_file, staging_dir): depot_package_name = CommonUtils.generate_package_name(package_name, version, platform) depot_pkg_dest_path = os.path.join(self._depot_df_path, depot_package_name) if not os.path.exists(depot_pkg_dest_path): os.makedirs(depot_pkg_dest_path) with open(manifest_file, "rb") as f: manifest = json.load(f) dirs_m = manifest[CommonConsts.MF_KEY_DIRS] files_m = manifest[CommonConsts.MF_KEY_FILES] for file_ in files_m: fullpath = os.path.join(staging_dir, file_[CommonConsts.MF_KEY_FILES_ATTR_PATH]) contents = open(fullpath, 'rb').read() sha1 = hashlib.sha1(contents).hexdigest() if sha1 != file_[CommonConsts.MF_KEY_FILES_ATTR_SHA1]: raise ChecksumError("FATAL: File modified in staging area before installation: {0}".format(file_[CommonConsts.MF_KEY_FILES_ATTR_PATH])) mode = CommonUtils.get_filepermission(fullpath) if mode != file_["mode"]: raise PermissionError("FATAL: SHA1 doesn't match for installed file: {0}".format(fullpath)) dest_file = os.path.join(depot_pkg_dest_path, sha1) shutil.copy(fullpath, dest_file) shutil.copy(manifest_file, self._depot_mf_path)
def _setup(self): try: self._manifest_filename = CommonUtils.generate_manifest_filename(self._name, self._version, self._platform, "json") self._depot_manifestfile_location = os.path.join(self._depot_location, CommonConsts.SW_DEPOT_MANIFEST_FILE_DIR) self._depot_datafile_location = os.path.join(self._depot_location, CommonConsts.SW_DEPOT_DATAFILES_DIR, CommonUtils.generate_package_name(self._name, self._version, self._platform)) self._etc_dir = os.path.join(self._install_dir, "etc", "packages") if not os.path.exists(self._etc_dir): os.makedirs(self._etc_dir) self._pkg_install_dir = self._install_dir self._is_already_installed = self._is_already_installed() self._temp_dir = os.path.join(self._pkg_install_dir, os.path.splitext(self._manifest_filename)[0] + "-INSTALL-TEMP") os.mkdir(self._temp_dir) self._manifest = self._get_manifest_object() except Exception as e: self._cleanup() self._log.error(e) raise e
def add(self, package_name, version, platform, staging_dir, manifest_filepath): try: manifest_filename = CommonUtils.generate_manifest_filename(package_name, version, platform, "json") if os.path.exists(os.path.join(self._depot_mf_path, manifest_filename)): raise PackageExistsError("Package manifest file already exists in depot. Package name : {0}, manifest file: {1}.\n\ Either uninstall the package first or use update command to install the package.".format(CommonUtils.generate_package_name(package_name, version, platform), manifest_filename)) input_manifest_file = os.path.join(manifest_filepath, manifest_filename) self._deploy_package(package_name, version, platform, input_manifest_file, staging_dir) except Exception as e: self._cleanup(package_name, version, platform, manifest_filename) raise e