print "No such file: %s" % package sys.exit(1) # Read config. if not os.path.exists(config.cfg_file): print "Please configure Spiff before using this tool." sys.exit(1) config.cfg.read(config.cfg_file) dbn = config.cfg.get('database', 'dbn') # Connect to MySQL and set up Spiff Guard. db = create_engine(dbn) guard = SpiffGuard.DB(db) # Set up an environment for the package manager. page_db = PageDB(guard) page = page_db.get('default') request = DummyRequest() api = ExtensionApi(object, guard = guard, page_db = page_db, request = request) # Init the package manager. pm = PackageManager(guard, api, package = SpiffPackage) pm.set_package_dir(config.package_dir) def pkg_check_dependencies(pm, package): print "Checking dependencies of %s..." % package.get_name(), error = False
def run(self): if not self._check_configured(): return if not self._check_installer_deleted(): return # Set up the session and database adapters. self.request.start_session() page_db = PageDB(self.get_guard()) user_db = UserDB(self.get_guard()) cache = CacheDB(self, self.get_guard()) self.bench.snapshot('set_up', 'Set-up time is %ss.') # Can not open some pages by addressing them directly. page_handle = self.request.get_data().get_str('page') if page_db.is_system_page_handle(page_handle): self.request.set_status(403) self.request.write('%s is a system page.' % repr(page_handle)) return # Find the current page using the given cgi variables. # If the specific site is not found, attempt to find a parent that # handles content recursively. page = page_db.get_responsible_page(page_handle) self.bench.snapshot('page_find', 'Looked up the page in %ss.') # If we still have no page, give 404. if page is None: self.request.set_status(404) self.request.write('Default page not found.') return self.set_requested_page(page) self.bench.snapshot('page_open', 'Opened the page in %ss.') # If the output of ALL extensions is cached (combined), there is no need # to redraw the page, including headers and footer. # Note that the cache only returns pages corresponding to the permissions # of the current user, so this is safe. if not self.request.has_post_data(): output = cache.get_page() self.bench.snapshot('cache_check', 'Spent %ss checking the cache.') if output is not None: self.request.write(output) self._render_footer() return self.bench.snapshot('cache_check', 'Spent %ss checking the cache.') # Set up the plugin manager (Integrator). Note that the constructor # of PackageManager also associates the api with a reference to the # PackageManager instance. api = ExtensionApi(self, guard = self.get_guard(), page_db = page_db, cache = cache, request = self.request) pm = PackageManager(self.get_guard(), api, package = SpiffPackage) pm.set_package_dir(config.package_dir) self.bench.snapshot('package_load', 'Package manager loaded in %ss.') # Ending up here the entire page was not cached. # Make sure that the caller has permission to retrieve this page. if page.get_attribute('private') and not self.current_user_may('view'): url = self.request.get_url(page = 'admin/login', refer_to = self.get_requested_uri()) return self.refer_to(url) self.bench.snapshot('permission_check', 'Permission checked in %ss.') # Render the HTML headers. self._render_head() self.bench.snapshot('render_header', 'Headers rendered in %ss.') # Render the layout. This also invokes the plugins. self.output += page.get_output(api) self.bench.snapshot('render_plugins', 'Plugins rendered in %ss.') # Cache the page (if it is cacheable). if page.is_cacheable() and len(self.request.get_headers()) == 0: cache.add_page(self.output) self.bench.snapshot('cache_add', 'Added to cache in %ss.') # Yippie. self.request.write(self.output) self._render_footer()