def install(self, source): url_parts = self.parse_url(source) dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') if not os.path.exists(dest_dir): mkdir(dest_dir, perms=0755) dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) try: self.download(source, dld_file) except urllib2.URLError as e: raise UnhandledSource(e.reason) except OSError as e: raise UnhandledSource(e.strerror) return extract(dld_file)
def install(self, source): url_parts = self.parse_url(source) dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) try: self.download(source, dld_file) except urllib2.URLError as e: return UnhandledSource(e.reason) except OSError as e: return UnhandledSource(e.strerror) finally: if os.path.isfile(dld_file): os.unlink(dld_file) return extract(dld_file)
def install(self, source, branch="master", dest=None, depth=None): url_parts = self.parse_url(source) branch_name = url_parts.path.strip("/").split("/")[-1] if dest: dest_dir = os.path.join(dest, branch_name) else: dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name) try: self.clone(source, dest_dir, branch, depth) except CalledProcessError as e: raise UnhandledSource(e) except OSError as e: raise UnhandledSource(e.strerror) return dest_dir
def branch(self, source, dest): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) if os.path.exists(dest): check_call(['bzr', 'pull', '--overwrite', '-d', dest, source]) else: check_call(['bzr', 'branch', source, dest])
def install(self, source, branch="master", dest=None, depth=None): url_parts = self.parse_url(source) branch_name = url_parts.path.strip("/").split("/")[-1] if dest: dest_dir = os.path.join(dest, branch_name) else: dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name) if not os.path.exists(dest_dir): mkdir(dest_dir, perms=0o755) try: self.clone(source, dest_dir, branch, depth) except GitCommandError as e: raise UnhandledSource(e.message) except OSError as e: raise UnhandledSource(e.strerror) return dest_dir
def clone(self, source, dest, branch, depth=None): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) if depth: Repo.clone_from(source, dest, branch=branch, depth=depth) else: Repo.clone_from(source, dest, branch=branch)
def install(self, source, dest=None, checksum=None, hash_type='sha1'): """ Download and install an archive file, with optional checksum validation. The checksum can also be given on the `source` URL's fragment. For example:: handler.install('http://example.com/file.tgz#sha1=deadbeef') :param str source: URL pointing to an archive file. :param str dest: Local destination path to install to. If not given, installs to `$CHARM_DIR/archives/archive_file_name`. :param str checksum: If given, validate the archive file after download. :param str hash_type: Algorithm used to generate `checksum`. Can be any hash alrgorithm supported by :mod:`hashlib`, such as md5, sha1, sha256, sha512, etc. """ url_parts = self.parse_url(source) dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') if not os.path.exists(dest_dir): mkdir(dest_dir, perms=0o755) dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) try: self.download(source, dld_file) except URLError as e: raise UnhandledSource(e.reason) except OSError as e: raise UnhandledSource(e.strerror) options = parse_qs(url_parts.fragment) for key, value in options.items(): if not six.PY3: algorithms = hashlib.algorithms else: algorithms = hashlib.algorithms_available if key in algorithms: if len(value) != 1: raise TypeError("Expected 1 hash value, not %d" % len(value)) expected = value[0] check_hash(dld_file, expected, key) if checksum: check_hash(dld_file, checksum, hash_type) return extract(dld_file, dest)
def clone(self, source, dest, branch="master", depth=None): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) if os.path.exists(dest): cmd = ['git', '-C', dest, 'pull', source, branch] else: cmd = ['git', 'clone', source, dest, '--branch', branch] if depth: cmd.extend(['--depth', depth]) check_call(cmd)
def install(self, source): url_parts = self.parse_url(source) branch_name = url_parts.path.strip("/").split("/")[-1] dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name) if not os.path.exists(dest_dir): mkdir(dest_dir, perms=0o755) try: self.branch(source, dest_dir) except OSError as e: raise UnhandledSource(e.strerror) return dest_dir
def branch(self, source, dest): url_parts = self.parse_url(source) # If we use lp:branchname scheme we need to load plugins if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) if url_parts.scheme == "lp": from bzrlib.plugin import load_plugins load_plugins() try: remote_branch = Branch.open(source) remote_branch.bzrdir.sprout(dest).open_branch() except Exception as e: raise e
def branch(self, source, dest, revno=None): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) cmd_opts = [] if revno: cmd_opts += ['-r', str(revno)] if os.path.exists(dest): cmd = ['bzr', 'pull'] cmd += cmd_opts cmd += ['--overwrite', '-d', dest, source] else: cmd = ['bzr', 'branch'] cmd += cmd_opts cmd += [source, dest] check_call(cmd)
def branch(self, source, dest): url_parts = self.parse_url(source) # If we use lp:branchname scheme we need to load plugins if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) if url_parts.scheme == "lp": from bzrlib.plugin import load_plugins load_plugins() try: local_branch = bzrdir.BzrDir.create_branch_convenience(dest) except errors.AlreadyControlDirError: local_branch = Branch.open(dest) try: remote_branch = Branch.open(source) remote_branch.push(local_branch) tree = workingtree.WorkingTree.open(dest) tree.update() except Exception as e: raise e
def clone(self, source, dest, branch): if not self.can_handle(source): raise UnhandledSource("Cannot handle {}".format(source)) repo = Repo.clone_from(source, dest) repo.git.checkout(branch)
def raise_unhandled(*args, **kwargs): raise UnhandledSource('test')