def process_packages(pkgmgr, pkg_type, pkg_names, src_dir, remove=False): exclude_string = ' .' names = [p.strip() for p in pkg_names.split(',')] for name in names: print "Processing %s ... " % name if pkg_type == 'client': pkg_dir = src_dir exclude_string = get_exclude_string(pkg_dir) elif pkg_type == 'test': # if the package is a test then look whether it is in client/tests # or client/site_tests pkg_dir = os.path.join(get_test_dir(name, src_dir), name) else: # for the profilers and deps pkg_dir = os.path.join(src_dir, name) pkg_name = pkgmgr.get_tarball_name(name, pkg_type) if not remove: # Tar the source and upload temp_dir = tempfile.mkdtemp() try: try: base_packages.check_diskspace(temp_dir) except error.RepoDiskFullError, e: msg = ("Temporary directory for packages %s does not have " "enough space available: %s" % (temp_dir, e)) raise error.RepoDiskFullError(msg) tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, temp_dir, exclude_string) pkgmgr.upload_pkg(tarball_path, update_checksum=True) finally:
def process_packages(pkgmgr, pkg_type, pkg_names, src_dir, action, dest_dir=None): """Method to upload or remove package depending on the flag passed to it. If tar_only is set to True, this routine is solely used to generate a tarball and compute the md5sum from that tarball. If the tar_only flag is True, then the remove flag is ignored. """ exclude_string = ' .' names = [p.strip() for p in pkg_names.split(',')] for name in names: print "process_packages: Processing %s ... " % name if pkg_type == 'client': pkg_dir = src_dir exclude_string = get_exclude_string(pkg_dir) elif pkg_type == 'test': # if the package is a test then look whether it is in client/tests # or client/site_tests pkg_dir = os.path.join(get_test_dir(name, src_dir), name) else: # for the profilers and deps pkg_dir = os.path.join(src_dir, name) pkg_name = pkgmgr.get_tarball_name(name, pkg_type) if action == ACTION_TAR_ONLY: # We don't want any pre-existing tarballs and checksums to # be repackaged, so we should purge these. exclude_string_tar = ( (' --exclude="**%s" --exclude="**%s.checksum" ' % (pkg_name, pkg_name)) + exclude_string) build_dir = get_build_dir(name, dest_dir, pkg_type) try: packages.check_diskspace(build_dir) except error.RepoDiskFullError as e: msg = ("Work_dir directory for packages %s does not have " "enough space available: %s" % (build_dir, e)) raise error.RepoDiskFullError(msg) tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, build_dir, exclude_string_tar) # Create the md5 hash too. md5sum = pkgmgr.compute_checksum(tarball_path) md5sum_filepath = os.path.join(build_dir, pkg_name + '.checksum') with open(md5sum_filepath, "w") as f: f.write(md5sum) elif action == ACTION_UPLOAD: # Tar the source and upload temp_dir = tempfile.mkdtemp() try: try: packages.check_diskspace(temp_dir) except error.RepoDiskFullError, e: msg = ("Temporary directory for packages %s does not have " "enough space available: %s" % (temp_dir, e)) raise error.RepoDiskFullError(msg) # Check if tarball already exists. If it does, and the checksum # is the same as what is in the checksum dictionary, then don't # create a tarball again. tarball_path = os.path.join(pkg_dir, pkg_name) if os.path.exists(tarball_path) and pkgmgr.compare_checksum( tarball_path): print("process_packages: Tarball %s already exists" % tarball_path) else: tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, temp_dir, exclude_string) pkgmgr.upload_pkg(tarball_path, update_checksum=True) finally:
repo_run_command(repo, 'mkdir -p %s' % remote_path, cd=False) def check_diskspace(repo, min_free=None): # Note: 1 GB = 10**9 bytes (SI unit). if min_free is None: min_free = global_config.global_config.get_config_value( 'PACKAGES', 'minimum_free_space', type=int, default=1) try: df = repo_run_command(repo, 'df -PB %d . | tail -1' % 10**9).stdout.split() free_space_gb = int(df[3]) except Exception, e: raise error.RepoUnknownError('Unknown Repo Error: %s' % e) if free_space_gb < min_free: raise error.RepoDiskFullError('Not enough disk space available ' '%sg < %sg' % (free_space_gb, min_free)) def check_write(repo): try: repo_testfile = '.repo_test_file' repo_run_command(repo, 'touch %s' % repo_testfile).stdout.strip() repo_run_command(repo, 'rm ' + repo_testfile) except error.CmdError: raise error.RepoWriteError('Unable to write to ' + repo) def trim_custom_directories(repo, older_than_days=None): if not repo: return