def install(self, package):
        """ Install the app, based on the user-given name. """

        # check if it is not an uninstallable package
        if package in settings.UNINSTALLABLE_PACKAGES:
            message = "{0} is not installable through appypi, sorry!".format(package)
            self.view.print_info(message)
            return

        # check if it is already installed
        if self.adb.app_is_installed(package):
            message = "{0} is already installed.".format(package)
            self.view.print_info(message)
            return

        # find if package exists in pypi
        name = self.find_package(package)
        if not name:
            message = "Can't find {0}".format(package)
            self.view.print_error_and_exit(message)
        else:
            self.view.print_info("Installing...")

        # create ~/.appypi/<package> directory
        self.create_app_dir()
        # create and source boostrap file ~/.appypi/<package>/bootstrap
        self.create_app_bootstrap()
        # create launchers file in ~/bin (depends on what the package defines)
        nb_launchers = self.create_launchers()

        if nb_launchers == 0:
            if self.requirement:
                message = "There's no launcher to be set for this package." "appypi won't install it..."
                self.view.print_info(message)
            else:
                message = (
                    "There's no launcher to be set for this package. "
                    "It is useless to install it through appypi, "
                    "as you wouldn't be able to use it. Mission aborted!"
                )
                # clean this mess and quit
                delete_dir(self.app_model.app_dir)
                self.view.print_error_and_exit(message)
        else:
            self.adb.add_app(self.app_model)
            self.view.print_info("Install successful!")
示例#2
0
    def check_launcher(self, binfile):
        """ Check if the launcher is installable. """
        apps_in_system = apps_in_path(binfile)

        if apps_in_system:
            # check if in a virtualenv: http://stackoverflow.com/q/1871549
            if hasattr(sys, 'real_prefix'):
                for path in apps_in_system[:]:
                    if path.startswith(sys.prefix) or binfile == 'appypi':
                        # virtualenv and appypi don't count, remove them
                        apps_in_system.remove(path)
            if not len(apps_in_system):
                apps_in_system = None

        if apps_in_system:
            message = "{0} seems to be installed already (pointing to: " \
                      "{1}). Please, remove this version before installing " \
                      "it with appypi, or maybe you can use it." \
                      .format(binfile, ' and '.join(apps_in_system))
            # clean this mess and quit
            delete_dir(self.app_model.app_dir)
            self.view.print_error_and_exit(message)