def fetch(self): try: fetcher = get_fetcher(self.url) except FetchError: # We might be passing a local dir path directly # which fetchers don't currently support self.directory = path(self.url) else: if hasattr(fetcher, "path") and fetcher.path.exists(): self.directory = path(fetcher.path) else: if not self.target_repo.exists(): self.target_repo.makedirs_p() self.directory = path(fetcher.fetch(self.target_repo)) if not self.directory.exists(): raise BuildError("Unable to locate {}. " "Do you need to set {}?".format( self.url, self.ENVIRON)) self.config_file = self.directory / self.CONFIG_FILE if not self.config_file.exists(): if self.OLD_CONFIG and (self.directory / self.OLD_CONFIG).exists(): self.config_file = (self.directory / self.OLD_CONFIG) self._name = self.config.name return self
def fetch(self): try: fetcher = get_fetcher(self.url) except FetchError: # We might be passing a local dir path directly # which fetchers don't currently support self.directory = path(self.url) else: if hasattr(fetcher, "path") and fetcher.path.exists(): self.directory = path(fetcher.path) else: if not self.target_repo.exists(): self.target_repo.makedirs_p() self.directory = path(fetcher.fetch(self.target_repo)) if not self.directory.exists(): raise OSError( "Unable to locate {}. " "Do you need to set {}?".format( self.url, self.ENVIRON)) self.config_file = self.directory / self.CONFIG_FILE if not self.config_file.exists(): if self.OLD_CONFIG and (self.directory / self.OLD_CONFIG).exists(): self.config_file = (self.directory / self.OLD_CONFIG) self._name = self.config.name return self
def fetch(self): try: fetcher = get_fetcher(self.url) except FetchError: # We might be passing a local dir path directly # which fetchers don't currently support self.directory = path(self.url) self.revision = RepoFetcher(self.url).get_revision(self.url) else: if hasattr(fetcher, "path") and fetcher.path.exists(): self.directory = path(fetcher.path) else: if not self.target_repo.exists(): self.target_repo.makedirs_p() self.directory = path(fetcher.fetch(self.target_repo)) self.fetched = True self.revision = fetcher.get_revision(self.directory) if not self.directory.exists(): raise BuildError( "Unable to locate {}. " "Do you need to set {}?".format( self.url, self.ENVIRON)) if self.config_file: self.config_file = self.directory / self.config_file if self.old_config_file: self.old_config_file = self.directory / self.old_config_file self._name = self.config.name return self
def download_item(args): series_dir = None if args.item.startswith(LAYER_PREFIX): dir_ = args.dir or CHARM_LAYERS_DIR name = args.item[len(LAYER_PREFIX):] elif args.item.startswith(INTERFACE_PREFIX): dir_ = args.dir or CHARM_INTERFACES_DIR name = args.item[len(INTERFACE_PREFIX):] else: dir_ = args.dir or CHARM_CHARMS_DIR if not args.item.startswith(CHARM_PREFIX): args.item = CHARM_PREFIX + args.item url_parts = args.item[len(CHARM_PREFIX):].split('/') name = url_parts[-1] if len(url_parts) == 2 and not url_parts[0].startswith('~'): series_dir = url_parts[0] elif len(url_parts) == 3: series_dir = url_parts[1] dir_ = dir_ or os.getcwd() dir_ = os.path.abspath(os.path.expanduser(dir_)) if not os.access(dir_, os.W_OK): print('Unable to write to {}'.format(dir_)) return 200 # Create series dir if we need to if series_dir: series_path = os.path.join(dir_, series_dir) if not os.path.exists(series_path): os.mkdir(series_path) dir_ = series_path # Abort if destination dir already exists final_dest_dir = os.path.join(dir_, name) if os.path.exists(final_dest_dir): print("{}: {}".format(ERR_DIR_EXISTS, final_dest_dir)) return 1 # Create tempdir for initial download tempdir = tempfile.mkdtemp() atexit.register(shutil.rmtree, tempdir) try: # Download the item fetcher = fetchers.get_fetcher(args.item) download_dir = fetcher.fetch(tempdir) except fetchers.FetchError: print("Can't find source for {}".format(args.item)) return 1 # Copy download dir to final destination dir shutil.copytree(download_dir, final_dest_dir, symlinks=True) rev = ' (rev: {})'.format(fetcher.revision) if fetcher.revision else '' if fetcher.revision: rev_file = path(final_dest_dir) / '.pull-source-rev' rev_file.write_text(fetcher.revision) print('Downloaded {}{} to {}'.format(args.item, rev, final_dest_dir))
def download_item(item, dir_): series_dir = None if item.startswith(LAYER_PREFIX): dir_ = dir_ or os.environ.get('LAYER_PATH') name = item[len(LAYER_PREFIX):] elif item.startswith(INTERFACE_PREFIX): dir_ = dir_ or os.environ.get('INTERFACE_PATH') name = item[len(INTERFACE_PREFIX):] else: dir_ = dir_ or os.environ.get('JUJU_REPOSITORY') if not item.startswith(CHARM_PREFIX): item = CHARM_PREFIX + item url_parts = item[len(CHARM_PREFIX):].split('/') name = url_parts[-1] if len(url_parts) == 2 and not url_parts[0].startswith('~'): series_dir = url_parts[0] elif len(url_parts) == 3: series_dir = url_parts[1] dir_ = dir_ or os.getcwd() dir_ = os.path.abspath(os.path.expanduser(dir_)) if not os.access(dir_, os.W_OK): print('Unable to write to {}'.format(dir_)) return 200 # Create series dir if we need to if series_dir: series_path = os.path.join(dir_, series_dir) if not os.path.exists(series_path): os.mkdir(series_path) dir_ = series_path # Abort if destination dir already exists final_dest_dir = os.path.join(dir_, name) if os.path.exists(final_dest_dir): print("{}: {}".format(ERR_DIR_EXISTS, final_dest_dir)) return 1 # Create tempdir for initial download tempdir = tempfile.mkdtemp() atexit.register(shutil.rmtree, tempdir) try: # Download the item fetcher = fetchers.get_fetcher(item) download_dir = fetcher.fetch(tempdir) except fetchers.FetchError: print("Can't find source for {}".format(item)) return 1 # Copy download dir to final destination dir shutil.copytree(download_dir, final_dest_dir, symlinks=True) print('Downloaded {} to {}'.format(item, final_dest_dir))
def download_item(item, dir_): series_dir = None if item.startswith(LAYER_PREFIX): dir_ = dir_ or os.environ.get('LAYER_PATH') name = item[len(LAYER_PREFIX):] elif item.startswith(INTERFACE_PREFIX): dir_ = dir_ or os.environ.get('INTERFACE_PATH') name = item[len(INTERFACE_PREFIX):] else: dir_ = dir_ or os.environ.get('JUJU_REPOSITORY') if not item.startswith(CHARM_PREFIX): item = CHARM_PREFIX + item url_parts = item[len(CHARM_PREFIX):].split('/') name = url_parts[-1] if len(url_parts) == 2 and not url_parts[0].startswith('~'): series_dir = url_parts[0] elif len(url_parts) == 3: series_dir = url_parts[1] dir_ = dir_ or os.getcwd() dir_ = os.path.abspath(os.path.expanduser(dir_)) if not os.access(dir_, os.W_OK): print('Unable to write to {}'.format(dir_)) return 200 # Create series dir if we need to if series_dir: series_path = os.path.join(dir_, series_dir) if not os.path.exists(series_path): os.mkdir(series_path) dir_ = series_path # Abort if destination dir already exists final_dest_dir = os.path.join(dir_, name) if os.path.exists(final_dest_dir): print("{}: {}".format(ERR_DIR_EXISTS, final_dest_dir)) return 1 # Create tempdir for initial download tempdir = tempfile.mkdtemp() atexit.register(shutil.rmtree, tempdir) try: # Download the item fetcher = fetchers.get_fetcher(item) download_dir = fetcher.fetch(tempdir) except fetchers.FetchError: print("Can't find source for {}".format(item)) return 1 # Copy download dir to final destination dir shutil.copytree(download_dir, final_dest_dir, symlinks=True) print('Downloaded {} to {}'.format(item, final_dest_dir))
def fetch(self, dir_): url = self.EXTRA_INFO_URL.format(self.entity) repo_url = get(url).json().get('bzr-url') if repo_url: try: fetcher = fetchers.get_fetcher(repo_url) except fetchers.FetchError: log.debug("No fetcher for %s, downloading from charmstore", repo_url) return super(CharmstoreRepoDownloader, self).fetch(dir_) else: return fetcher.fetch(dir_) return super(CharmstoreRepoDownloader, self).fetch(dir_)
def fetch(self, dir_): url = self.EXTRA_INFO_URL.format(self.entity) repo_url = get(url).json().get('bzr-url') if repo_url: try: fetcher = fetchers.get_fetcher(repo_url) except fetchers.FetchError: log.debug( "No fetcher for %s, downloading from charmstore", repo_url) return super(CharmstoreRepoDownloader, self).fetch(dir_) else: return fetcher.fetch(dir_) return super(CharmstoreRepoDownloader, self).fetch(dir_)
def fetch(self, dir_): for cfg in self.LAYER_CONFIGS: url = '{}/{}'.format(self.ARCHIVE_URL.format(self.entity), cfg) result = get(url) if not result.ok: continue repo_url = yaml.safe_load(result.text).get('repo') if not repo_url: continue try: fetcher = fetchers.get_fetcher(repo_url) except fetchers.FetchError: log.debug( 'Charm %s has a repo set in %s, but no fetcher could ' 'be found for the repo (%s).', self.entity, cfg, repo_url) break else: return fetcher.fetch(dir_) return super(CharmstoreLayerDownloader, self).fetch(dir_)
def fetch(self, dir_): for cfg in self.LAYER_CONFIGS: url = '{}/{}'.format( self.ARCHIVE_URL.format(self.entity), cfg) result = get(url) if not result.ok: continue repo_url = yaml.safe_load(result.text).get('repo') if not repo_url: continue try: fetcher = fetchers.get_fetcher(repo_url) except fetchers.FetchError: log.debug( 'Charm %s has a repo set in %s, but no fetcher could ' 'be found for the repo (%s).', self.entity, cfg, repo_url) break else: return fetcher.fetch(dir_) return super(CharmstoreLayerDownloader, self).fetch(dir_)
def fetch(self): try: # In order to lock the fetcher we need to adjust the self.url # to get the right thing. Curiously, self.url is actually # "layer:something" here, and so we can match on that. if self.lock: url = make_url_from_lock_for_layer(self.lock, self.use_branches) else: url = self.url fetcher = get_fetcher(url) except FetchError: # We might be passing a local dir path directly # which fetchers don't currently support self.directory = path(self.url) self.revision = RepoFetcher(self.url).get_revision(self.url) else: if hasattr(fetcher, "path") and fetcher.path.exists(): self.directory = path(fetcher.path) else: if not self.target_repo.exists(): self.target_repo.makedirs_p() self.directory = path(fetcher.fetch(self.target_repo)) self.fetched = True self.fetched_url = getattr(fetcher, "fetched_url", None) self.vcs = getattr(fetcher, "vcs", None) self.revision = fetcher.get_revision(self.directory) self.branch = fetcher.get_branch_for_revision( self.directory, self.revision) if not self.directory.exists(): raise BuildError("Unable to locate {}. " "Do you need to set {}?".format( self.url, self.ENVIRON)) if self.config_file: self.config_file = self.directory / self.config_file if self.old_config_file: self.old_config_file = self.directory / self.old_config_file self._name = self.config.name return self