def delete(self, base): ''' Deletes the selected overlay. @params base: Base dir where the overlay is installed. @rtype bool ''' mdir = path([base, self.parent.name]) source = self.src if 'file://' in source: pkg = source.replace('file://', '') else: pkg_name = self.parent.name + self.get_extension() pkg = path([self.config['storage'], pkg_name]) if os.path.ismount(mdir): result = self.mounter.umount([self.parent.name]) else: result = 1 shutil.rmtree(mdir) if self.clean_archive: if os.path.exists(pkg): os.unlink(pkg) return result
def test(self): self.assertEqual(path([]), '') self.assertEqual(path(['a']), 'a') self.assertEqual(path(['a', 'b']), 'a/b') self.assertEqual(path(['a/', 'b']), 'a/b') self.assertEqual(path(['/a/', 'b']), '/a/b') self.assertEqual(path(['/a', '/b/']), '/a/b') self.assertEqual(path(['/a/', 'b/']), '/a/b') self.assertEqual(path(['/a/','/b/']), '/a/b') self.assertEqual(path(['/a/','/b','c/']), '/a/b/c')
def test(self): self.assertEqual(path([]), '') self.assertEqual(path(['a']), 'a') self.assertEqual(path(['a', 'b']), 'a/b') self.assertEqual(path(['a/', 'b']), 'a/b') self.assertEqual(path(['/a/', 'b']), '/a/b') self.assertEqual(path(['/a', '/b/']), '/a/b') self.assertEqual(path(['/a/', 'b/']), '/a/b') self.assertEqual(path(['/a/', '/b/']), '/a/b') self.assertEqual(path(['/a/', '/b', 'c/']), '/a/b/c')
def mount(self, repo, dest=None, install=False, ovl_type=None, pkg=None): ''' Mounts an overlay to it's installation directory. @params repo: str of overlay name or "ALL". @params dest: str of optional destination dir. @params install: bool to reflect whether or not the overlay is being installed. @params ovl_type: str of optional overlay type. @params pkg: str of optional location of package to mount. @rtype int: reflects whether or not the overlay was mounted. ''' result = 1 selection = self._check_selection(repo) for i in selection: name = {'ovl': i} if i not in self.mountables and not install: self.output.error('Overlay "%(ovl)s" cannot be mounted!'\ % name) continue if dest: mdir = dest else: mdir = path([self.storage, i]) if not is_mounted(mdir): if install: args = copy.deepcopy(MOUNT_ARGS[ovl_type]) else: args = copy.deepcopy(MOUNT_ARGS[self.mountables[i]]) if not pkg: source = self.installed[i].sources[0].src if 'file://' in source: pkg = source.replace('file://', '') else: pkg = path([self.storage, i, source.get_extension()]) args.append(pkg) args.append(mdir) result = run_command(self.config, 'mount', args, cmd='mount') else: self.output.warn('Overlay "%(ovl)s" is already mounted!'\ % name) return result
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["git_addopts"] target = path([base, self.parent.name]) # git clone [-q] SOURCE TARGET args = ['clone'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.extend(cfg_opts.split()) args.append(self._fix_git_source(self.src)) args.append(target) if self.branch: args.append('-b') args.append(self.branch) success = False # adding cwd=base due to a new git bug in selinux due to # not having user_home_dir_t and portage_fetch_t permissions # but changing dir works around it. success = run_command(self.config, self.command(), args, cmd=self.type, cwd=base) self.output.debug("cloned git repo...success=%s" % str(success), 8) success = self.set_user(target) return self.postsync(success, cwd=target)
def checkout_location(): # Append '@' iff needed # Keeps users of SVN <1.6.5 happy in more cases (bug #313303) repo_part = self.parent.name if self.parent.name.find('@') != -1: repo_part = repo_part + '@' return path([base, repo_part])
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["cvs_addopts"] target = path([base, self.parent.name]) # cvs [-q] co -d SOURCE SCOPE args = [] if self.config['quiet']: args.append('-q') args.append('co') args.append('-d') if len(cfg_opts): args.extend(cfg_opts.split()) args.append(self.parent.name) args.append(self.branch) return self.postsync(run_command(self.config, self.command(), args, cwd=base, env=dict(CVSROOT=self.src), cmd=self.type), cwd=target)
def add(self, overlay, no_write=False): ''' Adds overlay information to the specified config file. @param overlay: layman.overlay.Overlay instance. @param no_write: boolean default=False usedto prevent circular recursion when add() is called from write() @return boolean: reflects a successful/failed write to the config file. ''' if self.repo_conf and self.repo_conf.has_section(overlay.name): return self.repo_conf.add_section(overlay.name) self.repo_conf.set(overlay.name, 'priority', str(overlay.priority)) self.repo_conf.set(overlay.name, 'location', path((self.storage, overlay.name))) self.repo_conf.set(overlay.name, 'layman-type', overlay.sources[0].type_key) if SYNC_TYPE: self.repo_conf.set(overlay.name, 'sync-type', SYNC_TYPE) self.repo_conf.set(overlay.name, 'sync-uri', overlay.sources[0].src) if overlay.sources[0].branch: self.repo_conf.set(overlay.name, 'branch', overlay.sources[0].branch) if SYNC_TYPE: #To maintain a desired structure, we have to do this check twice. self.repo_conf.set(overlay.name, 'auto-sync', self.config['auto_sync']) else: self.repo_conf.set(overlay.name, 'auto-sync', 'No') if not no_write: return self.write() return
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["mercurial_addopts"] target = path([base, self.parent.name]) src = self._fix_mercurial_source(self.src) # hg clone SOURCE TARGET if len(cfg_opts): args = ['clone'] + cfg_opts.split() + [src, target] else: args = ['clone', src, target] if self.branch: args.append('-r') args.append(self.branch) return self.postsync(run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def umount(self, repo, dest=None, sync=False): ''' Unmounts an overlay from it's installation directory. @params repo: str of overlay name or "ALL". @params dest: str of optional path to unmount. @params sync: bool to reflect whether or not the overlay is being synced. @rtype int: reflects whether or not it was a successful unmount. ''' result = 1 selection = self._check_selection(repo) for i in selection: name = {'ovl': i} if i not in self.mountables and not sync: self.output.error('Overlay "%(ovl)s" cannot be mounted!'\ % name) continue if dest: mdir = dest else: mdir = path([self.storage, i]) if is_mounted(mdir): args = ['-l', mdir] result = run_command(self.config, 'umount', args, cmd='umount') else: self.output.warn('Overlay "%(ovl)s" is already unmounted!'\ % name) return result
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 def checkout_location(): # Append '@' iff needed # Keeps users of SVN <1.6.5 happy in more cases (bug #313303) repo_part = self.parent.name if self.parent.name.find('@') != -1: repo_part = repo_part + '@' return path([base, repo_part]) cfg_opts = self.config["svn_syncopts"] self.target = checkout_location() # first check if an svn upgrade is needed. self.output.debug("SVN: check_upgrade() call", 4) self.check_upgrade(path([base, self.parent.name])) # svn up [-q] TARGET args = ['up'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.append(cfg_opts) args.append(self.target) return self.postsync( self.run_command(self.command(), args, cmd=self.type), cwd=self.target)
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["darcs_addopts"] target = path([base, self.parent.name]) if self.src.endswith("/"): src = self.src else: src = self.src + '/' # darcs get --partial SOURCE TARGET if len(cfg_opts): args = ['get', '--partial', cfg_opts, src, target] else: args = ['get', '--partial', src, target] return self.postsync( self.run_command(self.command(), args, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 # rsync OPTIONS [-q] SOURCE TARGET args = [ '-rlptDvz', '--progress', '--delete', '--delete-after', '--timeout=180', '--exclude=distfiles/*', '--exclude=local/*', '--exclude=packages/*' ] cfg_opts = self.config["rsync_syncopts"] target = path([base, self.parent.name]) if self.config['quiet']: args.append('-q') if len(cfg_opts): args.extend(cfg_opts.split()) args.append(self.src + '/') args.append(target) return self.postsync(run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) # First echo the new repository to CVS/Root args = [src, '>', '/CVS/Root'] result = self.run_command('echo', args, cmd='echo', cwd=target) if result == 0: location = src.split(':')[3] old_location = self.src.split(':/')[3] # Check if the repository location needs to be updated too. if not location == old_location: location = re.sub('/', '\/', location) old_location = re.sub('/', '\/', old_location) expression = 's/' + old_location + '/' + location + '/' # sed -i 's/<old_location>/<new_location>/ <target>/CVS/Repository args = ['-i', expression, '/CVS/Repository'] return self.run_command('sed', args, cmd='sed', cwd=target) return result
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["git_addopts"] target = path([base, self.parent.name]) # git clone [-q] SOURCE TARGET args = ['clone'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.append(cfg_opts) args.append(self._fix_git_source(self.src)) args.append(target) if self.branch: args.append('-b') args.append(self.branch) success = False # adding cwd=base due to a new git bug in selinux due to # not having user_home_dir_t and portage_fetch_t permissions # but changing dir works around it. success = run_command(self.config, self.command(), args,cmd=self.type, cwd=base) self.output.debug("cloned git repo...success=%s" % str(success), 8) success = self.set_user(target) return self.postsync(success, cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 def checkout_location(): # Append '@' iff needed # Keeps users of SVN <1.6.5 happy in more cases (bug #313303) repo_part = self.parent.name if self.parent.name.find('@') != -1: repo_part = repo_part + '@' return path([base, repo_part]) cfg_opts = self.config["svn_syncopts"] self.target = checkout_location() # first check if an svn upgrade is needed. self.output.debug("SVN: check_upgrade() call", 4) self.check_upgrade(path([base, self.parent.name])) # svn up [-q] TARGET args = ['up'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.extend(cfg_opts.split()) args.append(self.target) return self.postsync( run_command(self.config, self.command(), args, cmd=self.type), cwd=self.target)
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 super(SvnOverlay, self).add(base) cfg_opts = self.config["svn_addopts"] self.target = path([base, self.parent.name]) args = ['co'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.append(cfg_opts) if self.src.endswith("/"): src = self.src + '@' else: src = self.src + '/@' args.append(src) args.append(self.target) return self.postsync( self.run_command(self.command(), args, cmd=self.type), cwd=self.target)
def check_upgrade(self, target): '''Code to check the installed svn version and run "svn upgrade" if needed.''' file_to_run = _resolve_command(self.command(), self.output.error)[1] args = file_to_run + ' -q --version' pipe = Popen(args, shell=True, stdout=PIPE) if pipe: self.output.debug("SVN: check_upgrade()... have a valid pipe", 4) version = pipe.stdout.readline().strip('\n') self.output.debug("SVN: check_upgrade()... svn version found: %s" % version, 4) pipe.terminate() if version >= '1.7.0': self.output.debug("SVN: check_upgrade()... svn upgrade maybe", 4) _path = path([target,'.svn/wc.db']) if not os.path.exists(_path): self.output.info("An svn upgrade needs to be run...", 2) args = ["upgrade"] return self.run_command(self.command(), args, cwd=target, cmd="svn upgrade") return else: return
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 target = path([base, self.parent.name]) os.makedirs(target) return self.sync(base)
def delete(self, base): '''Delete the overlay.''' mdir = path([base, self.parent.name]) if not os.path.exists(mdir): self.output.warn('Directory ' + mdir + \ ' did not exist, no files deleted.') return False self.output.info('Deleting directory "%s"' % mdir, 2) shutil.rmtree(mdir) return True
def add(self, base): '''Add the overlay.''' mdir = path([base, self.parent.name]) if os.path.exists(mdir): self.output.error('Directory ' + mdir + ' already exists. Will not overwrite its contents!') return False os.makedirs(mdir) return True
def mounted(self): ''' Returns a dictionary of all mountable overlays and a boolean reflecting their mounted status. @rtype dict {'ovl1': True, 'ovl2': False,...} ''' mounted_ovls = {} for ovl in self.mountables: mdir = path([self.storage, ovl]) mounted_ovls[ovl] = is_mounted(mdir) return mounted_ovls
def add(self, base): '''Add the overlay.''' mdir = path([base, self.parent.name]) if os.path.exists(mdir): self.output.error( 'Directory ' + mdir + ' already exists. Will not overwrite its contents!') return False os.makedirs(mdir) return True
def add(self, overlay): ''' Adds overlay information to the specified config file. @param overlay: layman.overlay.Overlay instance. @return boolean: reflects a successful/failed write to the config file. ''' self.repo_conf.add_section(overlay.name) self.repo_conf.set(overlay.name, 'priority', str(overlay.priority)) self.repo_conf.set(overlay.name, 'location', path((self.storage, overlay.name))) self.repo_conf.set(overlay.name, 'sync-uri', overlay.sources[0].src) self.repo_conf.set(overlay.name, 'auto-sync', self.config['auto_sync']) return self.write()
def update(self, base, src): ''' Update overlay src-url @params base: base location where all overlays are installed. @params src: source URL. ''' self.output.debug("git.update(); starting...%s" % self.parent.name, 6) target = path([base, self.parent.name]) # git remote set-url <name> <newurl> <oldurl> args = ['remote', 'set-url', 'origin', self._fix_git_source(src), self._fix_git_source(self.src)] return self.run_command(self.command(), args, cmd=self.type, cwd=target)
def sync(self, base): ''' Sync overlay. @params base: string location where overlays are installed. @rtype bool ''' if not self.supported(): return 1 target = path([base, self.parent.name]) return self.postsync(self._add_unchecked(base), cwd=target)
def update(self, base, src): ''' Update overlay src-url @params base: base location where all overlays are installed. @params src: source URL. ''' self.output.debug("git.update(); starting...%s" % self.parent.name, 6) target = path([base, self.parent.name]) # git remote set-url <name> <newurl> <oldurl> args = ['remote', 'set-url', 'origin', self._fix_git_source(src), self._fix_git_source(self.src)] return run_command(self.config, self.command(), args, cmd=self.type, cwd=target)
def sync(self, base): ''' Sync overlay. @params base: string location where overlays are installed. @rtype bool ''' if not self.supported(): return 1 target = path([base, self.parent.name]) return self.postsync( self._add_unchecked(base), cwd=target)
def _fetch(self, base, archive_url, dest_dir): ''' Fetches overlay source archive. @params base: string of directory base for installed overlays. @params archive_url: string of URL where archive is located. @params dest_dir: string of destination of extracted archive. @rtype tuple (str of package location, bool to clean_archive) ''' ext = self.get_extension() if 'file://' not in archive_url: # set up ssl-fetch output map connector_output = { 'info': self.output.debug, 'error': self.output.error, 'kwargs-info': { 'level': 5 }, 'kwargs-debug': { 'level': 2 }, 'kwargs-error': { 'level': None }, } fetcher = Connector(connector_output, self.proxies, USERAGENT) success, archive, timestamp = fetcher.fetch_content(archive_url) pkg = path([base, self.parent.name + ext]) try: with fileopen(pkg, 'w+b') as out_file: out_file.write(archive) except Exception as error: raise Exception('Failed to store archive package in '\ '%(pkg)s\nError was: %(error)s'\ % ({'pkg': pkg, 'error': error})) else: self.clean_archive = False pkg = archive_url.replace('file://', '') return pkg
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 cfg_opts = self.config["bzr_syncopts"] target = path([base, self.parent.name]) # bzr pull --overwrite SOURCE if len(cfg_opts): args = ['pull', cfg_opts, '--overwrite', self.src] else: args = ['pull', '--overwrite', self.src] return self.postsync( self.run_command(self.command(), args, cwd=target, cmd=self.type), cwd=target)
def update(self, base, src): ''' Update overlay src-url @params base: base location where all overlays are installed. @params src: source URL. ''' self.output.debug("svn.update(); starting...%s" % self.parent.name, 6) target = path([base, self.parent.name]) # svn switch --relocate <oldurl> <newurl> args = ['switch', '--relocate', self._fix_svn_source(self.src), self._fix_svn_source(src)] return self.postsync( run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def add(self, base): ''' Add overlay. @params base: string location where overlays are installed. @rtype bool ''' if not self.supported(): return 1 target = path([base, self.parent.name]) if os.path.exists(target): raise Exception('Directory %(dir)s already exists. Will not '\ 'overwrite its contents!' % ({'dir': target})) return self.postsync(self._add_unchecked(base), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 cfg_opts = self.config["darcs_addopts"] target = path([base, self.parent.name]) # darcs pull --all SOURCE if len(cfg_opts): args = ['pull', '--all'] + cfg_opts.split() + [self.src] else: args = ['pull', '--all', self.src] return self.postsync( run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 target = path([base, self.parent.name]) args = [self.backend, '-o', target, '-r', self.repository, 'sync'] returncode = run_command(self.config, self.command(), args, cwd=target) if returncode: return returncode args = [self.backend, '-o', target, 'generate-tree'] return self.postsync( run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 target = path([base, self.parent.name]) args = [self.backend, '-o', target, '-r', self.repository, 'sync'] returncode = run_command(self.config, self.command(), args, cwd=target) if returncode: return returncode args = [self.backend, '-o', target, 'generate-tree'] return self.postsync(run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["bzr_addopts"] target = path([base, self.parent.name]) src = self._fix_bzr_source(self.src) # bzr get SOURCE TARGET if len(cfg_opts): args = ['branch'] + cfg_opts.split() + [src, target] else: args = ['branch', src, target] return self.postsync( run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' self.output.debug("git.sync(); starting...%s" % self.parent.name, 6) if not self.supported(): return 1 cfg_opts = self.config["git_syncopts"] target = path([base, self.parent.name]) args = ['pull'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.append(cfg_opts) return self.postsync( self.run_command(self.command(), args, cwd=target, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 cfg_opts = self.config["bzr_syncopts"] target = path([base, self.parent.name]) # bzr pull --overwrite SOURCE if len(cfg_opts): args = ['pull'] + cfg_opts.split() + ['--overwrite', self.src] else: args = ['pull', '--overwrite', self.src] return self.postsync(run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 cfg_opts = self.config["cvs_syncopts"] target = path([base, self.parent.name]) # cvs [-q] update -d args = [] if self.config['quiet']: args.append('-q') args.append('update') args.append('-d') if len(cfg_opts): args.append(cfg_opts) return self.postsync( self.run_command(self.command(), args, cwd=target, cmd=self.type), cwd=target)
def add(self, base): ''' Add overlay. @params base: string location where overlays are installed. @rtype bool ''' if not self.supported(): return 1 target = path([base, self.parent.name]) if os.path.exists(target): raise Exception('Directory %(dir)s already exists. Will not '\ 'overwrite its contents!' % ({'dir': target})) return self.postsync( self._add_unchecked(base), cwd=target)
def sync(self, base): '''Sync overlay.''' self.output.debug("git.sync(); starting...%s" % self.parent.name, 6) if not self.supported(): return 1 cfg_opts = self.config["git_syncopts"] target = path([base, self.parent.name]) args = ['pull'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.extend(cfg_opts.split()) return self.postsync( run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) # bzr bind SOURCE args = ['bind', self._fix_bzr_source(src)] if self.config['quiet']: args.append('--quiet') return self.postsync( run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def _fetch(self, base, archive_url, dest_dir): ''' Fetches overlay source archive. @params base: string of directory base for installed overlays. @params archive_url: string of URL where archive is located. @params dest_dir: string of destination of extracted archive. @rtype tuple (str of package location, bool to clean_archive) ''' ext = self.get_extension() if 'file://' not in archive_url: # set up ssl-fetch output map connector_output = { 'info': self.output.debug, 'error': self.output.error, 'kwargs-info': {'level': 5}, 'kwargs-debug': {'level': 2}, 'kwargs-error': {'level': None}, } fetcher = Connector(connector_output, self.proxies, USERAGENT) success, archive, timestamp = fetcher.fetch_content(archive_url) pkg = path([base, self.parent.name + ext]) try: with fileopen(pkg, 'w+b') as out_file: out_file.write(archive) except Exception as error: raise Exception('Failed to store archive package in '\ '%(pkg)s\nError was: %(error)s'\ % ({'pkg': pkg, 'error': error})) else: self.clean_archive = False pkg = archive_url.replace('file://', '') return pkg
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 cfg_opts = self.config["bzr_addopts"] target = path([base, self.parent.name]) src = self._fix_bzr_source(self.src) # bzr get SOURCE TARGET if len(cfg_opts): args = ['branch'] + cfg_opts.split() + [src, target] else: args = ['branch', src, target] return self.postsync(run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) # bzr bind SOURCE args = ['bind', self._fix_bzr_source(src)] if self.config['quiet']: args.append('--quiet') return self.postsync(run_command(self.config, self.command(), args, cmd=self.type), cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) # First echo the new repository to CVS/Root args = [src, '>', '/CVS/Root'] result = run_command(self.config, 'echo', args, cmd='echo', cwd=target) if result == 0: location = src.split(':')[3] old_location = self.src.split(':/')[3] # Check if the repository location needs to be updated too. if not location == old_location: location = re.sub('/', '\/', location) old_location = re.sub('/', '\/', old_location) expression = 's/' + old_location + '/' + location + '/' # sed -i 's/<old_location>/<new_location>/ <target>/CVS/Repository args = ['-i', expression, '/CVS/Repository'] return run_command(self.config, 'sed', args, cmd='sed', cwd=target) return result
def sync(self, base): '''Sync overlay.''' if not self.supported(): return 1 cfg_opts = self.config["cvs_syncopts"] target = path([base, self.parent.name]) # cvs [-q] update -d args = [] if self.config['quiet']: args.append('-q') args.append('update') args.append('-d') if len(cfg_opts): args.extend(cfg_opts.split()) return self.postsync(run_command(self.config, self.command(), args, cwd=target, cmd=self.type), cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) hgrc = ".hg/hgrc" old_src = re.sub('/', '\/', self._fix_mercurial_source(self.src)) new_src = re.sub('/', '\/', self._fix_mercurial_source(src)) expression = "s/" + old_src + "/" + new_src + "/" # sed -i 's/oldurl/newurl/' <target>/.hg/hgrc args = ['-i', expression, hgrc] # Run sed. return run_command(self.config, 'sed', args, cmd='sed', cwd=target)
def update(self, base, src): ''' Updates overlay src-url. @params base: base location where all overlays are installed. @params src: source URL. ''' if not self.supported(): return 1 target = path([base, self.parent.name]) hgrc = ".hg/hgrc" old_src = re.sub('/', '\/', self._fix_mercurial_source(self.src)) new_src = re.sub('/', '\/', self._fix_mercurial_source(src)) expression = "s/" + old_src + "/" + new_src + "/" # sed -i 's/oldurl/newurl/' <target>/.hg/hgrc args = ['-i', expression, hgrc] # Run sed. return self.run_command('sed', args, cmd='sed', cwd=target)
def add(self, base): '''Add overlay.''' if not self.supported(): return 1 super(SvnOverlay, self).add(base) cfg_opts = self.config["svn_addopts"] self.target = path([base, self.parent.name]) args = ['co'] if self.config['quiet']: args.append('-q') if len(cfg_opts): args.extend(cfg_opts.split()) src = self._fix_svn_source(self.src) args.append(src) args.append(self.target) return self.postsync( run_command(self.config, self.command(), args, cmd=self.type), cwd=self.target)
def __init__(self, output=None, stdout=None, stdin=None, stderr=None, config=None, read_configfile=False, quiet=False, quietness=4, verbose=False, nocolor=False, width=0, root=None): ''' Creates a bare config with defaults and a few output options. ''' if root is None: self.root = '' else: self.root = root self._defaults = { 'configdir': path([self.root, EPREFIX, '/etc/layman']), 'config': '%(configdir)s/layman.cfg', 'storage': path([self.root, EPREFIX, '/var/lib/layman']), 'cache': '%(storage)s/cache', 'local_list': '%(storage)s/overlays.xml', 'installed': '%(storage)s/installed.xml', 'protocol_filter': [], 'auto_sync': 'No', 'check_official': 'Yes', 'conf_type': 'repos.conf', 'db_type': 'xml', 'require_repoconfig': 'Yes', 'clean_archive': 'yes', 'make_conf': '%(storage)s/make.conf', 'repos_conf': path([self.root, EPREFIX, '/etc/portage/repos.conf/layman.conf']), 'conf_module': ['make_conf', 'repos_conf'], 'nocheck': 'yes', 'http_proxy': '', 'https_proxy': '', 'umask': '0022', 'news_reporter': 'portage', 'custom_news_pkg': '', 'gpg_detached_lists': 'https://api.gentoo.org/overlays/repositories.xml https://api.gentoo.org/overlays/repositories.xml.asc', 'gpg_signed_lists': '', 'overlays': 'https://api.gentoo.org/overlays/repositories.xml', 'overlay_defs': '%(configdir)s/overlays', 'bzr_command': path([self.root, EPREFIX, '/usr/bin/bzr']), 'cvs_command': path([self.root, EPREFIX, '/usr/bin/cvs']), 'darcs_command': path([self.root, EPREFIX, '/usr/bin/darcs']), 'git_command': path([self.root, EPREFIX, '/usr/bin/git']), 'g-common_command': path([self.root, EPREFIX, '/usr/bin/g-common']), 'g-sorcery_command': path([self.root, EPREFIX, '/usr/bin/g-sorcery']), 'mercurial_command': path([self.root, EPREFIX, '/usr/bin/hg']), # left blank due to squashfs only needing to mount the image. 'squashfs_command': '', 'rsync_command': path([self.root, EPREFIX, '/usr/bin/rsync']), 'svn_command': path([self.root, EPREFIX, '/usr/bin/svn']), 'tar_command': path([self.root, EPREFIX, '/bin/tar']), 't/f_options': [ 'check_official', 'clean_archive', 'nocheck', 'require_repoconfig' ], 'bzr_addopts': '', 'bzr_syncopts': '', 'cvs_addopts': '', 'cvs_syncopts': '', 'darcs_addopts': '', 'darcs_syncopts': '', 'git_addopts': '', 'git_syncopts': '', 'mercurial_addopts': '', 'mercurial_syncopts': '', 'rsync_syncopts': '', 'squashfs_addopts': '', 'squashfs_syncopts': '', 'svn_addopts': '', 'svn_syncopts': '', 'g-common_generateopts': '', 'g-common_syncopts': '', 'g-sorcery_generateopts': '', 'g-sorcery_syncopts': '', 'bzr_postsync': '', 'cvs_postsync': '', 'darcs_postsync': '', 'git_postsync': '', 'mercurial_postsync': '', 'rsync_postsync': '', 'squashfs_postsync': '', 'svn_postsync': '', 'tar_postsync': '', 'g-common_postsync': '', 'g-sorcery_postsync': '', 'git_user': '******', 'git_email': 'layman@localhost', 'support_url_updates': ['Bzr', 'cvs', 'Git', 'Mercurial', 'Subversion'], } self._options = { 'config': config if config else self._defaults['config'], 'stdout': stdout if stdout else sys.stdout, 'stdin': stdin if stdin else sys.stdin, 'stderr': stderr if stderr else sys.stderr, 'output': output if output else Message(), 'quietness': quietness, 'nocolor': nocolor, 'width': width, 'verbose': verbose, 'quiet': quiet, 'custom_news_func': None, } self._set_quietness(quietness) self.config = None if read_configfile: defaults = self.get_defaults() if "%(configdir)s" in defaults['config']: # fix the config path defaults['config'] = defaults['config'] \ % {'configdir': defaults['configdir']} self.read_config(defaults)