def get_package_tree(pkg): ''' Returns entire tree structure below that of the entered package as an html list. ''' try: # Check cache if not dbutil.cached_tables: dbutil.init_tables() html_tree = dbutil.get_html_tree(pkg['id']) if html_tree: return html_tree else: tree_pkg = _add_child_packages(pkg) html = '' if tree_pkg['children']: html = _add_child_bullets(html, tree_pkg) # Set cache (if there is a tree) if html: dbutil.cache_html_tree(pkg['id'],html) return html except Exception, e: log.exception("Error getting html tree: %s" % e) return ''
def command(self): self._load_config() # funny dance we need to do to make sure we've got a # configured session model.Session.remove() model.Session.configure(bind=model.meta.engine) dbutil.init_tables()
def command(self): self._load_config() model.Session.remove() model.Session.configure(bind=model.meta.engine) log = logging.getLogger('ckanext.ds_stats.ga') dbutil.init_tables() log.info("Set up statistics tables in main database")
def get_top_level_package(id): ''' Returns the top level package of the hierarchy of which the package with id is a child or an empty dict if this is the top level package''' current_id = id current_parent = get_parent_package(current_id) if not current_parent: return {} # Check cache if not dbutil.cached_tables: dbutil.init_tables() try: top_pkg_id = dbutil.get_top_pkg(id) if top_pkg_id: top_pkg = p.toolkit.get_action('package_show')( data_dict={'id': top_pkg_id}) return top_pkg else: while True: current_id = current_parent['id'] parent = get_parent_package(current_id) if not parent: break current_parent = parent dbutil.cache_top_pkg(id,current_parent['id']) return current_parent except Exception, e: log.debug("Error getting top level package: %s" % e) return {}
def command(self): self._load_config() model.Session.remove() model.Session.configure(bind=model.meta.engine) dbutil.init_tables() log.info("Set up statistics tables in main database")