def get_path(self, name): """Get path for an installed theme.""" try: path = utils.get_theme_path_real(name, self.site.themes_dirs) print(path) except Exception: print("not installed") return 0
def do_install_deps(self, url, name): """Install themes and their dependencies.""" data = self.get_json(url) # `name` may be modified by the while loop. origname = name installstatus = self.do_install(name, data) # See if the theme's parent is available. If not, install it while True: parent_name = utils.get_parent_theme_name(utils.get_theme_path_real(name, self.site.themes_dirs)) if parent_name is None: break try: utils.get_theme_path_real(parent_name, self.site.themes_dirs) break except: # Not available self.do_install(parent_name, data) name = parent_name if installstatus: LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(origname))
def do_install_deps(self, url, name): """Install themes and their dependencies.""" data = self.get_json(url) # `name` may be modified by the while loop. origname = name installstatus = self.do_install(name, data) # See if the theme's parent is available. If not, install it while True: parent_name = utils.get_parent_theme_name(utils.get_theme_path_real(name, self.site.themes_dirs)) if parent_name is None: break try: utils.get_theme_path_real(parent_name, self.site.themes_dirs) break except Exception: # Not available self.do_install(parent_name, data) name = parent_name if installstatus: LOGGER.notice('Remember to set THEME="{0}" in conf.py to use this theme.'.format(origname))
def do_uninstall(self, name): """Uninstall a theme.""" try: path = utils.get_theme_path_real(name, self.site.themes_dirs) except Exception: LOGGER.error('Unknown theme: {0}'.format(name)) return 1 LOGGER.warning('About to uninstall theme: {0}'.format(name)) LOGGER.warning('This will delete {0}'.format(path)) sure = utils.ask_yesno('Are you sure?') if sure: LOGGER.warning('Removing {0}'.format(path)) shutil.rmtree(path) return 0 return 1
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
def do_uninstall(self, name): """Uninstall a theme.""" try: path = utils.get_theme_path_real(name, self.site.themes_dirs) except Exception: LOGGER.error('Unknown theme: {0}'.format(name)) return 1 # Don't uninstall builtin themes (Issue #2510) blocked = os.path.dirname(utils.__file__) if path.startswith(blocked): LOGGER.error("Can't delete builtin theme: {0}".format(name)) return 1 LOGGER.warning('About to uninstall theme: {0}'.format(name)) LOGGER.warning('This will delete {0}'.format(path)) sure = utils.ask_yesno('Are you sure?') if sure: LOGGER.warning('Removing {0}'.format(path)) shutil.rmtree(path) return 0 return 1
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