def test_setup_base_cache(self): cache_dir = pu.setup_base_cache() try: self.assertEqual(cache_dir, os.environ['XDG_CACHE_HOME']) except KeyError: self.assertEqual( cache_dir, os.path.join(os.environ['HOME'], '.cache/.popper')) os.environ['POPPER_CACHE_DIR'] = '/tmp/popper' cache_dir = pu.setup_base_cache() self.assertEqual(cache_dir, '/tmp/popper') os.environ.pop('POPPER_CACHE_DIR')
def setup_vagrant_cache(wid): """Setup the vagrant cache directory based on the workflow id. Args: wid(str): The workflow id. Returns: str: The path to the cache dir. """ vagrant_cache = os.path.join(pu.setup_base_cache(), 'vagrant', wid) if not os.path.exists(vagrant_cache): os.makedirs(vagrant_cache) return vagrant_cache
def setup_singularity_cache(wid): """Setup the singularity cache directory based on the workflow id. Args: wid(str): The workflow id. Returns: str: The path to the cache dir. """ singularity_cache = os.path.join(pu.setup_base_cache(), 'singularity', wid) if not os.path.exists(singularity_cache): os.makedirs(singularity_cache) return singularity_cache
def download_actions(wf, dry_run, skip_clone, wid): """Clone actions that reference a repository. Args: wf(popper.parser.workflow): Instance of the Workflow class. dry_run(bool): True if workflow flag is being dry-run. skip_clone(bool): True if clonning action has to be skipped. wid(str): Returns: None """ actions_cache = os.path.join(pu.setup_base_cache(), 'actions', wid) cloned = set() infoed = False for _, a in wf.action.items(): if ('docker://' in a['uses'] or './' in a['uses'] or a['uses'] == 'sh'): continue url, service, user, repo, action_dir, version = scm.parse( a['uses']) repo_dir = os.path.join(actions_cache, service, user, repo) a['repo_dir'] = repo_dir a['action_dir'] = action_dir if dry_run: continue if skip_clone: if not os.path.exists(repo_dir): log.fail('The required action folder \'{}\' was not ' 'found locally.'.format(repo_dir)) continue if not infoed: log.info('[popper] Cloning action repositories') infoed = True if '{}/{}'.format(user, repo) in cloned: continue log.info('[popper] - {}/{}/{}@{}'.format(url, user, repo, version)) scm.clone(url, user, repo, repo_dir, version) cloned.add('{}/{}'.format(user, repo))