Ejemplo n.º 1
0
    def generate_manifest(self):
        manifest = {
            CommonConsts.MF_KEY_BUILD: [],
            CommonConsts.MF_KEY_DEPENDS: [],
            CommonConsts.MF_KEY_DIRS: [],
            CommonConsts.MF_KEY_FILES: []
        }
        if not os.path.exists(self._staging_dir):
            raise ResourceNotFoundError(
                "Staging directory path not available. Path: {0}".format(
                    self._staging_dir))
        for dirpath, dirnames, files in os.walk(self._staging_dir):
            dir_rel_path = os.path.relpath(dirpath, self._staging_dir)
            if dir_rel_path != ".":
                manifest[CommonConsts.MF_KEY_DIRS].append(
                    {CommonConsts.MF_KEY_FILES_ATTR_PATH: dir_rel_path})
            for file_ in files:
                fullpath = os.path.join(dirpath, file_)
                sha1 = HashGenerator(fullpath).generate_hash()
                filename = os.path.relpath(fullpath, self._staging_dir)
                mode = CommonUtils.get_filepermission(fullpath)
                manifest[CommonConsts.MF_KEY_FILES].append({
                    CommonConsts.MF_KEY_FILES_ATTR_PATH:
                    filename,
                    CommonConsts.MF_KEY_FILES_ATTR_SHA1:
                    sha1,
                    CommonConsts.MF_KEY_FILES_ATTR_MODE:
                    mode
                })

        if self._target_file_path is None:
            return json.dumps(manifest)
        self._write_to_file(manifest)
Ejemplo n.º 2
0
 def _verify_file(self, f):
     fullpath = self._get_destination_file(f)
     digest = hashlib.new("sha1")
     digest.update(open(fullpath, "rb").read())
     if digest.hexdigest() != f[CommonConsts.MF_KEY_FILES_ATTR_SHA1]:
         raise ChecksumError("FATAL: SHA1 doesn't match for installed file: {0}".format(fullpath))
     mode = CommonUtils.get_filepermission(fullpath)
     if mode != f[CommonConsts.MF_KEY_FILES_ATTR_MODE]:
         raise PermissionError("FATAL: Permission mode doesn't match for installed file: {0}".format(fullpath))
     return True
Ejemplo n.º 3
0
    def generate_manifest(self):
        manifest = {CommonConsts.MF_KEY_BUILD:[], CommonConsts.MF_KEY_DEPENDS:[], CommonConsts.MF_KEY_DIRS:[], CommonConsts.MF_KEY_FILES: []}
        if not os.path.exists(self._staging_dir):
            raise ResourceNotFoundError("Staging directory path not available. Path: {0}".format(self._staging_dir))
        for dirpath, dirnames, files in os.walk(self._staging_dir):
            dir_rel_path = os.path.relpath(dirpath, self._staging_dir)
            if dir_rel_path != ".":
                manifest[CommonConsts.MF_KEY_DIRS].append({CommonConsts.MF_KEY_FILES_ATTR_PATH:dir_rel_path})
            for file_ in files:
                fullpath = os.path.join(dirpath, file_)
                sha1 = HashGenerator(fullpath).generate_hash()
                filename = os.path.relpath(fullpath, self._staging_dir)
                mode = CommonUtils.get_filepermission(fullpath)
                manifest[CommonConsts.MF_KEY_FILES].append({CommonConsts.MF_KEY_FILES_ATTR_PATH: filename, CommonConsts.MF_KEY_FILES_ATTR_SHA1: sha1,
                                      CommonConsts.MF_KEY_FILES_ATTR_MODE: mode})

        if self._target_file_path is None:
            return json.dumps(manifest)
        self._write_to_file(manifest)
Ejemplo n.º 4
0
 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)