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
def do_install(self, url, name, show_install_notes=True): 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
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
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
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
def do_install(self, name, data): 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 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.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