def init_new_uris(self): """ For new uris not present in the uri_db: - Select a unique name inside recipes folder - Add an entry to the uri_db - If the uri is local, create the folder at the path. - If the uri is remote, clone the version repository with optional kwargs. Raises: PakitError: User attempted to use an unsupported URI. """ for uri in set(self.active_uris).difference(self.uri_db.keys()): repo = None kwargs = self.active_kwargs.get(uri, {}) try: repo = vcs_factory(uri, **kwargs) except PakitError: if uri.find('/') != -1 or uri.find('.') != -1: raise preferred = os.path.join(self.root, os.path.basename(uri)) path = self.uri_db.select_path(preferred) self.uri_db.add(uri, path, repo is not None, kwargs) if repo: repo.target = path PLOG('Downloading new recipes: %s', uri) with repo: pass else: PLOG('Indexing local recipes from: %s', path) try: os.makedirs(path) except OSError: pass self.uri_db.write()
def check_for_updates(self): """ Check if any of the active URIs needs updating. A recipe remote will be update if it is version controlled and ... - it has not been updated since interval - the kwargs between uri_db and active_kwargs differ """ need_updates = self.uri_db.need_updates(self.interval) vcs_uris = [uri for uri in self.uri_db if self.uri_db[uri]['is_vcs']] for uri in set(self.active_uris).intersection(vcs_uris): db_kwargs = self.uri_db[uri].get('kwargs', {}) kwargs = self.active_kwargs.get(uri, {}) repo = vcs_factory(uri, **kwargs) repo.target = self.uri_db[uri]['path'] if uri in need_updates or db_kwargs != kwargs: PLOG('Updating recipes from: %s.', uri) with repo: self.uri_db.update_time(uri) self.uri_db[uri]['kwargs'] = kwargs self.uri_db.write()
def test_vcs_factory_unsupported(): with pytest.raises(PakitError): vcs_factory(tc.TAR)
def test_vcs_factory(): print(os.listdir("/tmp")) repo = vcs_factory(tc.GIT) assert isinstance(repo, Git) assert repo.uri == tc.GIT