Exemplo n.º 1
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.notice('Downloading: ' + data[name])
            zip_file = BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.notice('Extracting: {0} into themes'.format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join('themes', name)
        else:
            try:
                theme_path = utils.get_theme_path(name)
            except:
                LOGGER.error("Can't find theme " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.notice('Copying {0} into themes'.format(theme_path))
            shutil.copytree(theme_path, dest_path)
        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This plugin has a sample config file.')
            print('Contents of the conf.py.sample file:\n')
            with codecs.open(confpypath, 'rb', 'utf-8') as fh:
                print(indent(pygments.highlight(
                    fh.read(), PythonLexer(), TerminalFormatter()), 4 * ' '))
            return True
Exemplo n.º 2
0
    def _execute(self, options, args):
        """Install theme into current site."""
        if requests is None:
            utils.LOGGER.error('This command requires the requests package be installed.')
            return False

        listing = options['list']
        url = options['url']
        if args:
            name = args[0]
        else:
            name = None

        if name is None and not listing:
            utils.LOGGER.error("This command needs either a theme name or the -l option.")
            return False
        data = requests.get(url).text
        data = json.loads(data)
        if listing:
            print("Themes:")
            print("-------")
            for theme in sorted(data.keys()):
                print(theme)
            return True
        else:
            if name in data:
                utils.makedirs('themes')
                utils.LOGGER.notice('Downloading: ' + data[name])
                zip_file = BytesIO()
                zip_file.write(requests.get(data[name]).content)
                utils.LOGGER.notice('Extracting: {0} into themes'.format(name))
                utils.extract_all(zip_file)
            else:
                utils.LOGGER.error("Can't find theme " + name)
                return False
Exemplo n.º 3
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info("Downloading '{0}'".format(data[name]))
            zip_file = io.BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info("Extracting '{0}' into themes/".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join(self.output_dir, name)
        else:
            dest_path = os.path.join(self.output_dir, name)
            try:
                theme_path = utils.get_theme_path(name)
                LOGGER.error("Theme '{0}' is already installed in {1}".format(name, theme_path))
            except Exception:
                LOGGER.error("Can't find theme {0}".format(name))

            return False

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This theme has a sample config file.  Integrate it with yours in order to make this theme work!')
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(
                        fh.read(), PythonLexer(), TerminalFormatter()),
                        4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return True
Exemplo n.º 4
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info("Downloading '{0}'".format(data[name]))
            zip_file = io.BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info("Extracting '{0}' into themes/".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join(self.output_dir, name)
        else:
            dest_path = os.path.join(self.output_dir, name)
            try:
                theme_path = utils.get_theme_path(name)
                LOGGER.error("Theme '{0}' is already installed in {1}".format(
                    name, theme_path))
            except Exception:
                LOGGER.error("Can't find theme {0}".format(name))

            return False

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice(
                'This theme has a sample config file.  Integrate it with yours in order to make this theme work!'
            )
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(
                        indent(
                            pygments.highlight(fh.read(), PythonLexer(),
                                               TerminalFormatter()), 4 * ' '))
                else:
                    print(indent(fh.read(), 4 * ' '))
        return True
Exemplo n.º 5
0
    def run(self, *args):
        """Install theme into current site."""

        parser = OptionParser(usage="nikola %s [options]" % self.name)
        parser.add_option("-l",
                          "--list",
                          dest="list",
                          action="store_true",
                          help="Show list of available themes.")
        parser.add_option("-n",
                          "--name",
                          dest="name",
                          help="Theme name",
                          default=None)
        parser.add_option(
            "-u",
            "--url",
            dest="url",
            help="URL for the theme repository"
            "(default: http://nikola.ralsina.com.ar/themes/index.json)",
            default='http://nikola.ralsina.com.ar/themes/index.json')
        (options, args) = parser.parse_args(list(args))

        listing = options.list
        name = options.name
        url = options.url

        if name is None and not listing:
            print "This command needs either the -n or the -l option."
            return False
        data = urllib2.urlopen(url).read()
        data = json.loads(data)
        if listing:
            print "Themes:"
            print "-------"
            for theme in sorted(data.keys()):
                print theme
            return True
        else:
            if name in data:
                if os.path.isfile("themes"):
                    raise IOError("'themes' isn't a directory!")
                elif not os.path.isdir("themes"):
                    try:
                        os.makedirs("themes")
                    except:
                        raise OSError("mkdir 'theme' error!")
                print 'Downloading: %s' % data[name]
                zip_file = StringIO()
                zip_file.write(urllib2.urlopen(data[name]).read())
                print 'Extracting: %s into themes' % name
                utils.extract_all(zip_file)
            else:
                print "Can't find theme %s" % name
                return False
Exemplo n.º 6
0
    def run(self, *args):
        """Install theme into current site."""
        if requests is None:
            print('To use the install_theme command, you need to install the "requests" package.')
            return
        parser = OptionParser(usage="nikola %s [options]" % self.name)
        parser.add_option("-l", "--list", dest="list",
            action="store_true",
            help="Show list of available themes.")
        parser.add_option("-n", "--name", dest="name",
            help="Theme name", default=None)
        parser.add_option("-u", "--url", dest="url",
            help="URL for the theme repository"
            "(default: http://nikola.ralsina.com.ar/themes/index.json)",
            default='http://nikola.ralsina.com.ar/themes/index.json')
        (options, args) = parser.parse_args(list(args))

        listing = options.list
        name = options.name
        url = options.url

        if name is None and not listing:
            print("This command needs either the -n or the -l option.")
            return False
        data = requests.get(url).text
        data = json.loads(data)
        if listing:
            print("Themes:")
            print("-------")
            for theme in sorted(data.keys()):
                print(theme)
            return True
        else:
            if name in data:
                if os.path.isfile("themes"):
                    raise IOError("'themes' isn't a directory!")
                elif not os.path.isdir("themes"):
                    try:
                        os.makedirs("themes")
                    except:
                        raise OSError("mkdir 'theme' error!")
                print('Downloading: %s' % data[name])
                zip_file = BytesIO()
                zip_file.write(requests.get(data[name]).content)
                print('Extracting: %s into themes' % name)
                utils.extract_all(zip_file)
            else:
                print("Can't find theme %s" % name)
                return False
Exemplo n.º 7
0
    def do_install(self, name, data):
        """Download and install a theme."""
        if name in data:
            utils.makedirs(self.output_dir)
            url = data[name]
            LOGGER.info("Downloading '{0}'".format(url))
            try:
                zip_data = requests.get(url).content
            except requests.exceptions.SSLError:
                LOGGER.warning(
                    "SSL error, using http instead of https (press ^C to abort)"
                )
                time.sleep(1)
                url = url.replace('https', 'http', 1)
                zip_data = requests.get(url).content

            zip_file = io.BytesIO()
            zip_file.write(zip_data)
            LOGGER.info("Extracting '{0}' into themes/".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join(self.output_dir, name)
        else:
            dest_path = os.path.join(self.output_dir, name)
            try:
                theme_path = utils.get_theme_path_real(name,
                                                       self.site.themes_dirs)
                LOGGER.error("Theme '{0}' is already installed in {1}".format(
                    name, theme_path))
            except Exception:
                LOGGER.error("Can't find theme {0}".format(name))

            return False

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice(
                'This theme has a sample config file.  Integrate it with yours in order to make this theme work!'
            )
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(
                        utils.indent(
                            pygments.highlight(fh.read(), PythonLexer(),
                                               TerminalFormatter()), 4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return True
Exemplo n.º 8
0
    def run(self, *args):
        """Install theme into current site."""

        parser = OptionParser()
        parser.add_option("-l", "--list", dest="list",
            action="store_true",
            help="Show list of available themes.")
        parser.add_option("-n", "--name", dest="name",
            help="Theme name", default=None)
        parser.add_option("-u", "--url", dest="url",
            help="URL for the theme repository"
            "(default: http://nikola.ralsina.com.ar/themes/index.json)",
            default='http://nikola.ralsina.com.ar/themes/index.json')
        (options, args) = parser.parse_args(list(args))

        listing = options.list
        name = options.name
        url = options.url

        if name is None and not listing:
            print "This command needs either the -n or the -l option."
            return False
        data = urllib2.urlopen(url).read()
        data = json.loads(data)
        if listing:
            print "Themes:"
            print "-------"
            for theme in sorted(data.keys()):
                print theme
            return True
        else:
            if name in data:
                if os.path.isfile("themes"):
                    raise IOError("'themes' isn't a directory!")
                elif not os.path.isdir("themes"):
                    try:
                        os.makedirs("themes")
                    except:
                        raise OSError("mkdir 'theme' error!")
                print 'Downloading: %s' % data[name]
                zip_file = StringIO()
                zip_file.write(urllib2.urlopen(data[name]).read())
                print 'Extracting: %s into themes' % name
                utils.extract_all(zip_file)
            else:
                print "Can't find theme %s" % name
                return False
Exemplo n.º 9
0
    def _execute(self, options, args):
        """Install theme into current site."""
        if requests is None:
            print('This command requires the requests package be installed.')
            return False

        listing = options['list']
        url = options['url']
        if args:
            name = args[0]
        else:
            name = None

        if name is None and not listing:
            print("This command needs either a theme name or the -l option.")
            return False
        data = requests.get(url).text
        data = json.loads(data)
        if listing:
            print("Themes:")
            print("-------")
            for theme in sorted(data.keys()):
                print(theme)
            return True
        else:
            if name in data:
                if os.path.isfile("themes"):
                    raise IOError("'themes' isn't a directory!")
                elif not os.path.isdir("themes"):
                    try:
                        os.makedirs("themes")
                    except:
                        raise OSError("mkdir 'theme' error!")
                print('Downloading: ' + data[name])
                zip_file = BytesIO()
                zip_file.write(requests.get(data[name]).content)
                print('Extracting: {0} into themes'.format(name))
                utils.extract_all(zip_file)
            else:
                print("Can't find theme " + name)
                return False
Exemplo n.º 10
0
    def _execute(self, options, args):
        """Install theme into current site."""
        if requests is None:
            print('This command requires the requests package be installed.')
            return False

        listing = options['list']
        url = options['url']
        if args:
            name = args[0]
        else:
            name = None

        if name is None and not listing:
            print("This command needs either a theme name or the -l option.")
            return False
        data = requests.get(url).text
        data = json.loads(data)
        if listing:
            print("Themes:")
            print("-------")
            for theme in sorted(data.keys()):
                print(theme)
            return True
        else:
            if name in data:
                if os.path.isfile("themes"):
                    raise IOError("'themes' isn't a directory!")
                elif not os.path.isdir("themes"):
                    try:
                        os.makedirs("themes")
                    except:
                        raise OSError("mkdir 'theme' error!")
                print('Downloading: ' + data[name])
                zip_file = BytesIO()
                zip_file.write(requests.get(data[name]).content)
                print('Extracting: {0} into themes'.format(name))
                utils.extract_all(zip_file)
            else:
                print("Can't find theme " + name)
                return False
Exemplo n.º 11
0
    def do_install(self, name, data):
        """Download and install a theme."""
        if name in data:
            utils.makedirs(self.output_dir)
            url = data[name]
            LOGGER.info("Downloading '{0}'".format(url))
            try:
                zip_data = requests.get(url).content
            except requests.exceptions.SSLError:
                LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
                time.sleep(1)
                url = url.replace('https', 'http', 1)
                zip_data = requests.get(url).content

            zip_file = io.BytesIO()
            zip_file.write(zip_data)
            LOGGER.info("Extracting '{0}' into themes/".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join(self.output_dir, name)
        else:
            dest_path = os.path.join(self.output_dir, name)
            try:
                theme_path = utils.get_theme_path_real(name, self.site.themes_dirs)
                LOGGER.error("Theme '{0}' is already installed in {1}".format(name, theme_path))
            except Exception:
                LOGGER.error("Can't find theme {0}".format(name))

            return False

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This theme has a sample config file.  Integrate it with yours in order to make this theme work!')
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(
                        fh.read(), PythonLexer(), TerminalFormatter()),
                        4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return True
Exemplo n.º 12
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            utils.LOGGER.notice('Downloading: ' + data[name])
            zip_file = BytesIO()
            zip_file.write(requests.get(data[name]).content)
            utils.LOGGER.notice('Extracting: {0} into plugins'.format(name))
            utils.extract_all(zip_file, 'plugins')
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                utils.LOGGER.error("Can't find plugin " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                utils.LOGGER.error("{0} is already installed".format(name))
                return False

            utils.LOGGER.notice('Copying {0} into plugins'.format(plugin_path))
            shutil.copytree(plugin_path, dest_path)
            return True
Exemplo n.º 13
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info("Downloading: " + data[name])
            zip_file = io.BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info("Extracting: {0} into themes".format(name))
            utils.extract_all(zip_file)
            dest_path = os.path.join("themes", name)
        else:
            try:
                theme_path = utils.get_theme_path(name)
            except:
                LOGGER.error("Can't find theme " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.info("Copying {0} into themes".format(theme_path))
            shutil.copytree(theme_path, dest_path)
        confpypath = os.path.join(dest_path, "conf.py.sample")
        if os.path.exists(confpypath):
            LOGGER.notice(
                "This theme has a sample config file.  Integrate it with yours in order to make this theme work!"
            )
            print("Contents of the conf.py.sample file:\n")
            with io.open(confpypath, "r", encoding="utf-8") as fh:
                if self.site.colorful:
                    print(indent(pygments.highlight(fh.read(), PythonLexer(), TerminalFormatter()), 4 * " "))
                else:
                    print(indent(fh.read(), 4 * " "))
        return True
Exemplo n.º 14
0
    def do_install(self, url, name, show_install_notes=True):
        """Download and install a plugin."""
        data = self.get_json(url)
        if name in data:
            utils.makedirs(self.output_dir)
            url = data[name]
            LOGGER.info("Downloading '{0}'".format(url))
            try:
                zip_data = requests.get(url).content
            except requests.exceptions.SSLError:
                LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
                time.sleep(1)
                url = url.replace('https', 'http', 1)
                zip_data = requests.get(url).content

            zip_file = io.BytesIO()
            zip_file.write(zip_data)
            LOGGER.info('Extracting: {0} into {1}/'.format(name, self.output_dir))
            utils.extract_all(zip_file, self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
        else:
            LOGGER.error("Can't find plugin " + name)
            return 1

        reqpath = os.path.join(dest_path, 'requirements.txt')
        if os.path.exists(reqpath):
            LOGGER.notice('This plugin has Python dependencies.')
            LOGGER.info('Installing dependencies with pip...')
            try:
                subprocess.check_call((sys.executable, '-m', 'pip', 'install', '-r', reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error('Could not install the dependencies.')
                print('Contents of the requirements.txt file:\n')
                with io.open(reqpath, 'r', encoding='utf-8') as fh:
                    print(utils.indent(fh.read(), 4 * ' '))
                print('You have to install those yourself or through a '
                      'package manager.')
            else:
                LOGGER.info('Dependency installation succeeded.')

        reqnpypath = os.path.join(dest_path, 'requirements-nonpy.txt')
        if os.path.exists(reqnpypath):
            LOGGER.notice('This plugin has third-party '
                          'dependencies you need to install '
                          'manually.')
            print('Contents of the requirements-nonpy.txt file:\n')
            with io.open(reqnpypath, 'r', encoding='utf-8') as fh:
                for l in fh.readlines():
                    i, j = l.split('::')
                    print(utils.indent(i.strip(), 4 * ' '))
                    print(utils.indent(j.strip(), 8 * ' '))
                    print()

            print('You have to install those yourself or through a package '
                  'manager.')

        req_plug_path = os.path.join(dest_path, 'requirements-plugins.txt')
        if os.path.exists(req_plug_path):
            LOGGER.notice('This plugin requires other Nikola plugins.')
            LOGGER.info('Installing plugins...')
            plugin_failure = False
            try:
                with io.open(req_plug_path, 'r', encoding='utf-8') as inf:
                    for plugname in inf.readlines():
                        plugin_failure = self.do_install(url, plugname.strip(), show_install_notes) != 0
            except Exception:
                plugin_failure = True
            if plugin_failure:
                LOGGER.error('Could not install a plugin.')
                print('Contents of the requirements-plugins.txt file:\n')
                with io.open(req_plug_path, 'r', encoding='utf-8') as fh:
                    print(utils.indent(fh.read(), 4 * ' '))
                print('You have to install those yourself manually.')
            else:
                LOGGER.info('Dependency installation succeeded.')

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath) and show_install_notes:
            LOGGER.notice('This plugin has a sample config file.  Integrate it with yours in order to make this plugin work!')
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(
                        fh.read(), PythonLexer(), TerminalFormatter()),
                        4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return 0
Exemplo n.º 15
0
    def do_install(self, url, name):
        data = self.get_json(url)
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info("Downloading: " + data[name])
            zip_file = BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info("Extracting: {0} into {1}/".format(name, self.output_dir))
            utils.extract_all(zip_file, self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                LOGGER.error("Can't find plugin " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.info("Copying {0} into plugins".format(plugin_path))
            shutil.copytree(plugin_path, dest_path)

        reqpath = os.path.join(dest_path, "requirements.txt")
        if os.path.exists(reqpath):
            LOGGER.notice("This plugin has Python dependencies.")
            LOGGER.info("Installing dependencies with pip...")
            try:
                subprocess.check_call(("pip", "install", "-r", reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error("Could not install the dependencies.")
                print("Contents of the requirements.txt file:\n")
                with codecs.open(reqpath, "rb", "utf-8") as fh:
                    print(indent(fh.read(), 4 * " "))
                print("You have to install those yourself or through a " "package manager.")
            else:
                LOGGER.info("Dependency installation succeeded.")
        reqnpypath = os.path.join(dest_path, "requirements-nonpy.txt")
        if os.path.exists(reqnpypath):
            LOGGER.notice("This plugin has third-party " "dependencies you need to install " "manually.")
            print("Contents of the requirements-nonpy.txt file:\n")
            with codecs.open(reqnpypath, "rb", "utf-8") as fh:
                for l in fh.readlines():
                    i, j = l.split("::")
                    print(indent(i.strip(), 4 * " "))
                    print(indent(j.strip(), 8 * " "))
                    print()

            print("You have to install those yourself or through a package " "manager.")
        confpypath = os.path.join(dest_path, "conf.py.sample")
        if os.path.exists(confpypath):
            LOGGER.notice(
                "This plugin has a sample config file.  Integrate it with yours in order to make this plugin work!"
            )
            print("Contents of the conf.py.sample file:\n")
            with codecs.open(confpypath, "rb", "utf-8") as fh:
                if self.site.colorful:
                    print(indent(pygments.highlight(fh.read(), PythonLexer(), TerminalFormatter()), 4 * " "))
                else:
                    print(indent(fh.read(), 4 * " "))
        return True
Exemplo n.º 16
0
    def do_install(self, url, name, show_install_notes=True):
        """Download and install a plugin."""
        data = self.get_json(url)
        if name in data:
            utils.makedirs(self.output_dir)
            url = data[name]
            LOGGER.info("Downloading '{0}'".format(url))
            try:
                zip_data = requests.get(url).content
            except requests.exceptions.SSLError:
                LOGGER.warning(
                    "SSL error, using http instead of https (press ^C to abort)"
                )
                time.sleep(1)
                url = url.replace('https', 'http', 1)
                zip_data = requests.get(url).content

            zip_file = io.BytesIO()
            zip_file.write(zip_data)
            LOGGER.info('Extracting: {0} into {1}/'.format(
                name, self.output_dir))
            utils.extract_all(zip_file, self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                LOGGER.error("Can't find plugin " + name)
                return 1

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return 1

            LOGGER.info('Copying {0} into plugins'.format(plugin_path))
            shutil.copytree(plugin_path, dest_path)

        reqpath = os.path.join(dest_path, 'requirements.txt')
        if os.path.exists(reqpath):
            LOGGER.notice('This plugin has Python dependencies.')
            LOGGER.info('Installing dependencies with pip...')
            try:
                subprocess.check_call(
                    (sys.executable, '-m', 'pip', 'install', '-r', reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error('Could not install the dependencies.')
                print('Contents of the requirements.txt file:\n')
                with io.open(reqpath, 'r', encoding='utf-8') as fh:
                    print(utils.indent(fh.read(), 4 * ' '))
                print('You have to install those yourself or through a '
                      'package manager.')
            else:
                LOGGER.info('Dependency installation succeeded.')

        reqnpypath = os.path.join(dest_path, 'requirements-nonpy.txt')
        if os.path.exists(reqnpypath):
            LOGGER.notice('This plugin has third-party '
                          'dependencies you need to install '
                          'manually.')
            print('Contents of the requirements-nonpy.txt file:\n')
            with io.open(reqnpypath, 'r', encoding='utf-8') as fh:
                for l in fh.readlines():
                    i, j = l.split('::')
                    print(utils.indent(i.strip(), 4 * ' '))
                    print(utils.indent(j.strip(), 8 * ' '))
                    print()

            print('You have to install those yourself or through a package '
                  'manager.')

        req_plug_path = os.path.join(dest_path, 'requirements-plugins.txt')
        if os.path.exists(req_plug_path):
            LOGGER.notice('This plugin requires other Nikola plugins.')
            LOGGER.info('Installing plugins...')
            try:
                with io.open(req_plug_path, 'r', encoding='utf-8') as inf:
                    for plugname in inf.readlines():
                        self.do_install(url, plugname, show_install_notes)
            except subprocess.CalledProcessError:
                LOGGER.error('Could not install a plugin.')
                print('Contents of the requirements-plugins.txt file:\n')
                with io.open(req_plug_path, 'r', encoding='utf-8') as fh:
                    print(utils.indent(fh.read(), 4 * ' '))
                print('You have to install those yourself manually.')
            else:
                LOGGER.info('Dependency installation succeeded.')

        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath) and show_install_notes:
            LOGGER.notice(
                'This plugin has a sample config file.  Integrate it with yours in order to make this plugin work!'
            )
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(
                        utils.indent(
                            pygments.highlight(fh.read(), PythonLexer(),
                                               TerminalFormatter()), 4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return 0
Exemplo n.º 17
0
    def do_install(self, name, data):
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.notice('Downloading: ' + data[name])
            zip_file = BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.notice('Extracting: {0} into plugins'.format(name))
            utils.extract_all(zip_file, 'plugins')
            dest_path = os.path.join('plugins', name)
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                LOGGER.error("Can't find plugin " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.notice('Copying {0} into plugins'.format(plugin_path))
            shutil.copytree(plugin_path, dest_path)

        reqpath = os.path.join(dest_path, 'requirements.txt')
        if os.path.exists(reqpath):
            LOGGER.notice('This plugin has Python dependencies.')
            LOGGER.notice('Installing dependencies with pip...')
            try:
                subprocess.check_call(('pip', 'install', '-r', reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error('Could not install the dependencies.')
                print('Contents of the requirements.txt file:\n')
                with codecs.open(reqpath, 'rb', 'utf-8') as fh:
                    print(indent(fh.read(), 4 * ' '))
                print('You have to install those yourself or through a '
                      'package manager.')
            else:
                LOGGER.notice('Dependency installation succeeded.')
        reqnpypath = os.path.join(dest_path, 'requirements-nonpy.txt')
        if os.path.exists(reqnpypath):
            LOGGER.notice('This plugin has third-party '
                          'dependencies you need to install '
                          'manually.')
            print('Contents of the requirements-nonpy.txt file:\n')
            with codecs.open(reqnpypath, 'rb', 'utf-8') as fh:
                for l in fh.readlines():
                    i, j = l.split('::')
                    print(indent(i.strip(), 4 * ' '))
                    print(indent(j.strip(), 8 * ' '))
                    print()

            print('You have to install those yourself or through a package '
                  'manager.')
        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath):
            LOGGER.notice('This plugin has a sample config file.')
            print('Contents of the conf.py.sample file:\n')
            with codecs.open(confpypath, 'rb', 'utf-8') as fh:
                if sys.platform == 'win32':
                    print(
                        indent(
                            pygments.highlight(fh.read(), PythonLexer(),
                                               TerminalFormatter()), 4 * ' '))
                else:
                    print(indent(fh.read(), 4 * ' '))
        return True
Exemplo n.º 18
0
    def do_install(self, url, name, show_install_notes=True):
        """Download and install a plugin."""
        data = self.get_json(url)
        if name in data:
            utils.makedirs(self.output_dir)
            url = data[name]
            LOGGER.info("Downloading '{0}'".format(url))
            try:
                zip_data = requests.get(url).content
            except requests.exceptions.SSLError:
                LOGGER.warning("SSL error, using http instead of https (press ^C to abort)")
                time.sleep(1)
                url = url.replace("https", "http", 1)
                zip_data = requests.get(url).content

            zip_file = io.BytesIO()
            zip_file.write(zip_data)
            LOGGER.info("Extracting: {0} into {1}/".format(name, self.output_dir))
            utils.extract_all(zip_file, self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                LOGGER.error("Can't find plugin " + name)
                return 1

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return 1

            LOGGER.info("Copying {0} into plugins".format(plugin_path))
            shutil.copytree(plugin_path, dest_path)

        reqpath = os.path.join(dest_path, "requirements.txt")
        if os.path.exists(reqpath):
            LOGGER.notice("This plugin has Python dependencies.")
            LOGGER.info("Installing dependencies with pip...")
            try:
                subprocess.check_call(("pip", "install", "-r", reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error("Could not install the dependencies.")
                print("Contents of the requirements.txt file:\n")
                with io.open(reqpath, "r", encoding="utf-8") as fh:
                    print(utils.indent(fh.read(), 4 * " "))
                print("You have to install those yourself or through a " "package manager.")
            else:
                LOGGER.info("Dependency installation succeeded.")
        reqnpypath = os.path.join(dest_path, "requirements-nonpy.txt")
        if os.path.exists(reqnpypath):
            LOGGER.notice("This plugin has third-party " "dependencies you need to install " "manually.")
            print("Contents of the requirements-nonpy.txt file:\n")
            with io.open(reqnpypath, "r", encoding="utf-8") as fh:
                for l in fh.readlines():
                    i, j = l.split("::")
                    print(utils.indent(i.strip(), 4 * " "))
                    print(utils.indent(j.strip(), 8 * " "))
                    print()

            print("You have to install those yourself or through a package " "manager.")
        confpypath = os.path.join(dest_path, "conf.py.sample")
        if os.path.exists(confpypath) and show_install_notes:
            LOGGER.notice(
                "This plugin has a sample config file.  Integrate it with yours in order to make this plugin work!"
            )
            print("Contents of the conf.py.sample file:\n")
            with io.open(confpypath, "r", encoding="utf-8") as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(fh.read(), PythonLexer(), TerminalFormatter()), 4 * " "))
                else:
                    print(utils.indent(fh.read(), 4 * " "))
        return 0
Exemplo n.º 19
0
    def do_install(self, url, name, show_install_notes=True):
        data = self.get_json(url)
        if name in data:
            utils.makedirs(self.output_dir)
            LOGGER.info('Downloading: ' + data[name])
            zip_file = io.BytesIO()
            zip_file.write(requests.get(data[name]).content)
            LOGGER.info('Extracting: {0} into {1}/'.format(name, self.output_dir))
            utils.extract_all(zip_file, self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
        else:
            try:
                plugin_path = utils.get_plugin_path(name)
            except:
                LOGGER.error("Can't find plugin " + name)
                return False

            utils.makedirs(self.output_dir)
            dest_path = os.path.join(self.output_dir, name)
            if os.path.exists(dest_path):
                LOGGER.error("{0} is already installed".format(name))
                return False

            LOGGER.info('Copying {0} into plugins'.format(plugin_path))
            shutil.copytree(plugin_path, dest_path)

        reqpath = os.path.join(dest_path, 'requirements.txt')
        if os.path.exists(reqpath):
            LOGGER.notice('This plugin has Python dependencies.')
            LOGGER.info('Installing dependencies with pip...')
            try:
                subprocess.check_call(('pip', 'install', '-r', reqpath))
            except subprocess.CalledProcessError:
                LOGGER.error('Could not install the dependencies.')
                print('Contents of the requirements.txt file:\n')
                with io.open(reqpath, 'r', encoding='utf-8') as fh:
                    print(utils.indent(fh.read(), 4 * ' '))
                print('You have to install those yourself or through a '
                      'package manager.')
            else:
                LOGGER.info('Dependency installation succeeded.')
        reqnpypath = os.path.join(dest_path, 'requirements-nonpy.txt')
        if os.path.exists(reqnpypath):
            LOGGER.notice('This plugin has third-party '
                          'dependencies you need to install '
                          'manually.')
            print('Contents of the requirements-nonpy.txt file:\n')
            with io.open(reqnpypath, 'r', encoding='utf-8') as fh:
                for l in fh.readlines():
                    i, j = l.split('::')
                    print(utils.indent(i.strip(), 4 * ' '))
                    print(utils.indent(j.strip(), 8 * ' '))
                    print()

            print('You have to install those yourself or through a package '
                  'manager.')
        confpypath = os.path.join(dest_path, 'conf.py.sample')
        if os.path.exists(confpypath) and show_install_notes:
            LOGGER.notice('This plugin has a sample config file.  Integrate it with yours in order to make this plugin work!')
            print('Contents of the conf.py.sample file:\n')
            with io.open(confpypath, 'r', encoding='utf-8') as fh:
                if self.site.colorful:
                    print(utils.indent(pygments.highlight(
                        fh.read(), PythonLexer(), TerminalFormatter()),
                        4 * ' '))
                else:
                    print(utils.indent(fh.read(), 4 * ' '))
        return True