def __init__(self, root, storage=grow_storage.AUTO, env=None, load_extensions=True): self.deprecated = deprecated.DeprecationManager(self.logger.warn) self._yaml = utils.SENTINEL self.storage = storage self.root = (root if self.storage.is_cloud_storage else os.path.abspath(root)) self.env = (env if env else environment.Env( environment.EnvConfig(host='localhost'))) self.locales = locales.Locales(pod=self) self.catalogs = catalog_holder.Catalogs(pod=self) self._jinja_env_lock = threading.RLock() self._podcache = None self._features = features.Features(disabled=[ self.FEATURE_TRANSLATION_STATS, self.FEATURE_OLD_SLUGIFY, ]) self._experiments = features.Features(default_enabled=False) self._extensions_controller = ext_controller.ExtensionController(self) if self.exists: # Modify sys.path for built-in extension support. _ext_dir = self.abs_path(self.extensions_dir) if os.path.exists(_ext_dir): sys.path.insert(0, _ext_dir) # Load the features from the podspec. self._load_features() # Load the experiments from the podspec. self._load_experiments() # Ensure preprocessors are loaded when pod is initialized. # Preprocessors may modify the environment in ways that are required by # data files (e.g. yaml constructors). Avoid loading extensions using # `load_extensions=False` to permit `grow install` to be used to # actually install extensions, prior to loading them. if load_extensions and self.exists: self.list_preprocessors() # Load extensions, ignore local extensions during install. self._load_extensions(load_extensions) try: update_checker = updater.Updater(self) update_checker.verify_required_version() except PodDoesNotExistError: pass # Pod doesn't exist yet, simply pass.
def upgrade(pod_path): """Check for and upgrade grow when available.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) try: pod = pods.Pod(root, storage=storage.FileStorage) with pod.profile.timer('grow_upgrade'): pod.logger.info('Checking for newer versions of grow.') update_checker = updater.Updater(pod) if not update_checker.check_for_updates(force=True): pod.logger.info('No updates found. Running Grow v{}'.format( config.VERSION)) except pods.Error as err: raise click.ClickException(str(err)) return pod
def server_activate(self): super(CallbackHTTPServer, self).server_activate() _, port = self.server_address self.pod.env.port = port with timer.Timer() as router_time: self.pod.router.add_all(concrete=False) self.pod.logger.info('{} routes built in {:.3f} s'.format( len(self.pod.router.routes), router_time.secs)) url = print_server_ready_message(self.pod, self.pod.env.host, port) if self.open_browser: start_browser_in_thread(url) if self.update_check: update_checker = updater.Updater(self.pod) check_func = update_checker.check_for_updates thread = threading.Thread(target=check_func, args=(True, )) thread.start()
def server_activate(self): super(CallbackHTTPServer, self).server_activate() _, port = self.server_address self.pod.env.port = port with timer.Timer() as router_time: try: self.pod.router.add_all(concrete=False) except bulk_errors.BulkErrors as err: bulk_errors.display_bulk_errors(err) sys.exit(-1) self.pod.logger.info('{} routes built in {:.3f} s'.format( len(self.pod.router.routes), router_time.secs)) url, extra_urls = print_server_ready_message(self.pod, self.pod.env.host, port) if self.open_browser: start_browser_in_thread(url) for extra_url in extra_urls: start_browser_in_thread(extra_url) if self.update_check: update_checker = updater.Updater(self.pod) check_func = update_checker.check_for_updates thread = threading.Thread(target=check_func, args=(True,)) thread.start()
def setUp(self): self.dir_path = testing.create_test_pod_dir() self.pod = pods.Pod(self.dir_path, storage=storage.FileStorage) self.updater = updater.Updater(self.pod)