Skip to content

Commit

Permalink
Merge "Use hard links instead of copy" into R2.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 26, 2015
2 parents 095c93d + f96b6ff commit c6f22ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions build/libs/packager/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, **kwargs):
self.id = kwargs.get('build_id', 999)
self.sku = kwargs.get('sku', 'grizzly')
self.branch = kwargs.get('branch', 9.9)
self.copy_use_hard_link = kwargs.get('copy_use_hard_link', False)
self.store = self.expanduser(kwargs['store_dir'])
self.abs_pkg_dirs = self.expanduser(kwargs['absolute_package_dir'])
self.cache_base_dir = self.expanduser(kwargs['cache_base_dir'])
Expand Down
15 changes: 11 additions & 4 deletions build/libs/packager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ def create_dir(dirname, recreate=False):
os.makedirs(dirname)
return dirname


def copyfiles(self, files, dirs):
def copyfiles(self, files, dirs, as_link=True):
files = self.get_as_list(files)
dirs = self.get_as_list(dirs)
copyiter = itertools.product(files, dirs)
for item in copyiter:
shutil.copy2(*item)
dst = os.path.join(item[1], os.path.basename(item[0]))
if as_link and self.copy_use_hard_link:
log.debug('copy_as_hard_link %s %s' % (item[0], dst))
if os.path.exists(dst):
log.warn('copy_as_hard_link: destination exists: %s, removing before link' % dst)
os.unlink(dst)
os.link(item[0], dst)
else:
shutil.copy2(*item)

def read_async(self, fd):
'''read data from a file descriptor, ignoring EAGAIN errors'''
Expand Down Expand Up @@ -384,7 +391,7 @@ def copy_pkg_files(self, pkginfo, error=True):
continue
pkgfile = pkginfo[pkg]['found_at']
destdirs = pkginfo[pkg]['repo']
self.copyfiles(pkgfile, destdirs)
self.copyfiles(pkgfile, destdirs, as_link=False)

def copy_built_pkg_files(self, targets=None, destdirs=None,
extra_dirs=None, skips=None, error=True):
Expand Down
4 changes: 4 additions & 0 deletions build/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def set_cli_defaults(self):
'build_id' : random.randint(1000, 9999),
'sku' : skuname,
'branch' : None,
'copy_use_hard_link' : False,
'store_dir' : os.path.join(git_local_repo, 'build'),
'absolute_package_dir' : None,
'contrail_package_dir' : None,
Expand Down Expand Up @@ -288,6 +289,9 @@ def define_args(self):
aparser.add_argument('--fail-on-error', '-e',
action='store_true',
help='Abort Packager from continuing on first instance of failure')
aparser.add_argument('--copy-use-hard-link', '-l',
action='store_true',
help='Use hard links instead of cp when duplicating artifacts like .tgz, .deb, and .rpm')
aparser.add_argument('--post-job', '-j',
action='store',
default=None,
Expand Down

0 comments on commit c6f22ea

Please sign in to comment.