def log_repo_update(self, msg): elements = msg.body.split('\t') if len(elements) != 3: logging.warning("got bad message: %s", elements) return repo_id = elements[1] owner = get_repo_owner(repo_id) logging.info('repo: %s was updated by %s' % (repo_id, owner))
def generate_catalog(): """ Generate entire catalog and put it into DB cache """ repos_all = [ r for r in seafile_api.get_repo_list(0, MAX_INT) if get_repo_owner(r.id) != 'system' ] return [ generate_catalog_entry(repo) for repo in sorted( repos_all, key=lambda x: x.last_modify, reverse=False) ]
def clean_up_catalog(): """ Remove catalog entries for non existed repos """ reconnect_db() repo_ids = [ r.id for r in seafile_api.get_repo_list(0, MAX_INT) if get_repo_owner(r.id) != 'system' ] i = 0 for ce in Catalog.objects.get_all(): if ce.repo_id not in repo_ids: ce.delete() i += 1 return i
def get_catalog(): catalog = [] repos_all = seafile_api.get_repo_list(0, MAX_INT) #repos_all = [seafile_api.get_repo('a6d4ae75-b063-40bf-a3d9-dde74623bb2c')] for repo in repos_all: try: proj = {} proj["id"] = repo.id proj["name"] = repo.name email = get_repo_owner(repo.id) proj["owner"] = email user_name = get_user_name(email) if user_name != email: proj["owner_name"] = user_name proj["in_progress"] = True commits = get_commits(repo.id, 0, 1) commit = get_commit(repo.id, repo.version, commits[0].id) dir = fs_mgr.load_seafdir(repo.id, repo.version, commit.root_id) file = dir.lookup(ARCHIVE_METADATA_TARGET) if file: md = parse_markdown(file.get_content()) if md: # Author a = md.get("Author") if a: a_list = strip_uni(a.strip()).split('\n') authors = [] for _ in a_list: author = {} aa = _.split(';') author['name'] = aa[0] if len(aa) > 1 and aa[1].strip(): author['affs'] = [x.strip() for x in aa[1].split('|')] author['affs'] = [x for x in author['affs'] if x ] authors.append(author) if a: proj["authors"] = authors # Description d = strip_uni(md.get("Description")) if d: proj["description"] = d # Comments c = strip_uni(md.get("Comments")) if c: proj["comments"] = c #Title t = strip_uni(md.get("Title")) if t: proj["title"] = t del proj["in_progress"] proj["is_certified"] = is_certified_by_repo_id(repo.id) else: if DEBUG: print "No %s for repo %s found" % (ARCHIVE_METADATA_TARGET, repo.name) catalog.append(proj) except Exception as err: msg = "repo_name: %s, id: %s, err: %s" % ( repo.name, repo.id, str(err) ) logging.error (msg) if DEBUG: print msg return catalog
def generate_catalog_entry(repo): """ Generate catalog entry in for the repo DB """ reconnect_db() proj = {} try: proj["id"] = repo.id proj["name"] = repo.name email = get_repo_owner(repo.id) proj["owner"] = email user_name = get_user_name(email) if user_name != email: proj["owner_name"] = user_name proj["in_progress"] = True proj["modified"] = repo.last_modify commits = get_commits(repo.id, 0, 1) commit = get_commit(repo.id, repo.version, commits[0].id) dir = fs_mgr.load_seafdir(repo.id, repo.version, commit.root_id) file = dir.lookup(ARCHIVE_METADATA_TARGET) if file: md = file.get_content().decode('utf-8') md = parse_markdown(md) if md: # Author a = md.get("Author") if a: a_list = a.split('\n') authors = [] for _ in a_list: author = {} aa = _.split(';') author['name'] = aa[0] if len(aa) > 1 and aa[1].strip(): author['affs'] = [ x.strip() for x in aa[1].split('|') ] author['affs'] = [x for x in author['affs'] if x] authors.append(author) if a: proj["authors"] = authors # Description d = md.get("Description") if d: proj["description"] = d # Comments c = md.get("Comments") if c: proj["comments"] = c # Title t = md.get("Title") if t: proj["title"] = t del proj["in_progress"] # Year y = md.get("Year") if y: proj["year"] = y # Institute i = md.get("Institute") if i: proj["institute"] = i proj["is_certified"] = is_certified_by_repo_id(repo.id) # add or update project metadata in DB c = Catalog.objects.add_or_update_by_repo_id(repo.id, email, proj, repo.name) # Catalog_id proj["catalog_id"] = str(c.catalog_id) except Exception: msg = "repo_name: %s, id: %s" % (repo.name, repo.id) logging.error(msg) logging.error(traceback.format_exc()) return proj