Esempio n. 1
0
def run():
    if not check_git():
        print("Error! Git executable not found!")
        print("Please ensure you have git installed!")
        sys.exit(1)

    m = Manifest()
    if args.command in commands:
        commands[args.command]['method']()
    else:
        print("Valid command required!")
        parser.print_usage()
        sys.exit(1)
    m.save()
Esempio n. 2
0
    def __init__(self, force=False):
        self.__dict__ = self.__borg_state

        self.c = Config()
        self.force = force
        self.b = Bank()
        self.m = Manifest()
        self.cache = {}
        self._installed = {}
        self._working_dirs = set()
Esempio n. 3
0
    def __init__(self):
        self.__dict__ = self.__borg_state

        self.c = Config()
        self.g = Git()
        self.m = Manifest()
Esempio n. 4
0
class PackageHandler:
    __borg_state = {}

    def __init__(self, force=False):
        self.__dict__ = self.__borg_state

        self.c = Config()
        self.force = force
        self.b = Bank()
        self.m = Manifest()
        self.cache = {}
        self._installed = {}
        self._working_dirs = set()

    def _check_deps(self, pkg):
        """Checks that the dependencies are installed for a package."""
        all_deps = True
        for dep in pkg.requires:
            if dep not in self.m.get('PackageHandler', 'installed'):
                print("!! Error, dependency '{0}' not found for package" +
                " '{1}'!".format(dep, pkg.name))
                all_deps = False

        if not pkg.check_system_requirements():
            print("!! Error, system requirements not satisfied for" +
            " '{0}'!".format(pkg.name))
            all_deps = False

        return all_deps

    def _get_package(self, package):
        """Returns a package object, either loading as needed or from cache."""
        if package in self.cache:
            return self.cache[package]
        else:
            p = self.b.get_package(package)
            self.cache[package] = p
            return p

    def _cleanup(self, directory):
        """Given a directory, clean it up without prejudice.

        Will only clean up directries in the vamp infrastructure."""
        if directory in self._working_dirs:
            shutil.rmtree(directory)
            self._working_dirs.remove(directory)
        else:
            raise OSError("Error! Attempt to remove directory outside of vamp" + \
                    "infrastructure! '{0}'".format(directory))

    def _get_workdir(self, package):
        """Given a package name, get a working directory for it."""
        wdir = tempfile.mkdtemp(prefix=package)
        self._working_dirs.add(wdir)
        ensure_path(wdir)
        return wdir

    def _get_installdir(self, package):
        """Given a package name, get the installation directory for it."""
        indir = "{0}/{1}".format(self.c.get('paths', 'install', True), package)
        self._working_dirs.add(indir)
        ensure_path(indir)
        return indir

    def _install(self, package):
        """Installs a package."""
        pkg = self._get_package(package)
        if pkg is None:
            print("Error! Unable to find package '{0}'!".format(package))
            sys.exit(1)

        if self._check_deps(pkg):
            print("> Installing '{0}'...".format(pkg.name))
            working_dir = self._get_workdir(package)
            install_dir = self._get_installdir(package)
            bins = pkg.install(working_dir, install_dir, self.c.get('globals',
                'verbose'))
            if bins is None:
                print("!! Error installing package '{0}'!".format(package))
                print("!! No binaries specified!")
                self._cleanup(working_dir)
                self._cleanup(install_dir)
            else:
                self._cleanup(working_dir)
        else:
            print("!! Error installing package '{0}'".format(package) + \
                    ", problem with dependencies!")
            sys.exit(1)

    def _find_build_deps(self, pkg):
        """Internal, recursive, function for finding the build deps of a
        package."""
        deps = []
        deps.append(pkg.package_name)
        for req in pkg.requires:
            if req not in self._installed:
                deppkg = self._get_package(req)
                deps.extend(self._find_build_deps(deppkg))
        return deps

    def build_deps(self, package):
        """Given a package, build the dependencies needed to install it."""
        pkg = self._get_package(package)
        # Pre-cache the installed packages
        self._installed = self.m.get('PackageHandler', 'installed')
        return list(set(self._find_build_deps(pkg)))

    def install(self, packages):
        """Given a list of packages, install them.

        If the list is not dependency resolved, you will probably get errors
        on install."""
        for p in packages:
            self._install(p)
Esempio n. 5
0
class Bank:
    __borg_state = {}
    BLOODBANK = ".bloodbank"
    GITHUBBANK = ".github"

    def __init__(self):
        self.__dict__ = self.__borg_state

        self.c = Config()
        self.g = Git()
        self.m = Manifest()

    def init_bank(self, bank=None, force=False):
        """Initializes a bank.

        'bank' should be a string of the format 'user/repo'.

        If 'bank' is not specified, will init the main bloodbank.
        """
        clone_to = None
        url = None
        if bank is None:
            url = self.c.get("urls", "bloodbank")
            clone_to = "{0}/{1}".format(self.c.get("paths", "bank"), self.BLOODBANK)
        else:
            url = self.g.get_url(bank)
            clone_to = "{0}/{1}/{2}".format(self.c.get("paths", "bank"), self.GITHUBBANK, bank)

        if url is None:
            print("Error! No valid URL found for '{0}'!".format(bank))
            sys.exit(1)

        if os.path.isdir(clone_to):
            if force:
                print("!! Bank directory exists, but overwriting because " + "of --force")
                shutil.rmtree(clone_to)
                self.g.clone(url, clone_to)
            else:
                print("!! Bank directory exists, using existing")
        else:
            self.g.clone(url, clone_to)

        self.m.set("bank", "repos", {bank: {"url": url, "dir": clone_to, "lastup": time.time()}})

    def get_package(self, package):
        """Given a package name, import the package object and return it."""
        # We have to run through a number of sources to get the package
        filename = "{0}/{1}/.bank/{2}.py".format(self.c.get("paths", "bank", True), self.BLOODBANK, package)
        if os.path.isfile(filename):
            return kitten_importer(filename, package)
        else:
            if self.g.get_url(package) is not None:
                appname = package.split("/")[-1]
                self.init_bank(package)
                filename = "{0}/{1}/.bank/{2}.py".format(self.c.get("paths", "bank", True), self.GITHUBBANK, appname)
                if os.path.isfile(filename):
                    return kitten_importer(filename, appname)
        return None

    def update(self, bank=None):
        """Update a bank.

        'bank' should be a string of the format 'user/repo'.

        If 'bank' is none, will update all repos.
        """
        repos = self.m.get("bank", "repos", {})
        if bank is None:
            for repo in repos:
                if os.path.isdir(repos[repo]["dir"]):
                    self.g.update(repos[repo]["dir"])
                else:
                    print(
                        "Error! No bank found at '{0}', yet manifest " + "reports one there!".format(repos[repo]["dir"])
                    )
                    # FIXME : Would be nice to suggest a way to fix this
                    sys.exit(1)
        else:
            if bank in repos:
                repo = repos[bank]
                if os.path.isdir(repo["dir"]):
                    self.g.update(repo["dir"])
                else:
                    print("Error! No bank found at '{0}, yet manifest " + "reports one there!".format(repo["dir"]))
                    # FIXME : Same as above
                    sys.exit(1)
            else:
                print("Error! Bank '{0}' not found in manifest!".format(bank))