def Contributor_add(av, name): record = Contributor.gql('WHERE avkey = :1', av).get() if record is None: NewDist = Contributor(avkey = av, avname = name) NewDist.put() token = "contr_auth_%s" % av memcache.set(token, True)
def _sample_ecosystem(self): """ Creates an ecosystem of some sample work, pool, edition, and author objects that all know each other. """ # make some authors [bob], ignore = Contributor.lookup(self._db, u"Bitshifter, Bob") bob.family_name, bob.display_name = bob.default_names() [alice], ignore = Contributor.lookup(self._db, u"Adder, Alice") alice.family_name, alice.display_name = alice.default_names() edition_std_ebooks, pool_std_ebooks = self._edition( DataSource.STANDARD_EBOOKS, Identifier.URI, with_license_pool=True, with_open_access_download=True, authors=[]) edition_std_ebooks.title = u"The Standard Ebooks Title" edition_std_ebooks.subtitle = u"The Standard Ebooks Subtitle" edition_std_ebooks.add_contributor(alice, Contributor.AUTHOR_ROLE) edition_git, pool_git = self._edition(DataSource.PROJECT_GITENBERG, Identifier.GUTENBERG_ID, with_license_pool=True, with_open_access_download=True, authors=[]) edition_git.title = u"The GItenberg Title" edition_git.subtitle = u"The GItenberg Subtitle" edition_git.add_contributor(bob, Contributor.AUTHOR_ROLE) edition_git.add_contributor(alice, Contributor.AUTHOR_ROLE) edition_gut, pool_gut = self._edition(DataSource.GUTENBERG, Identifier.GUTENBERG_ID, with_license_pool=True, with_open_access_download=True, authors=[]) edition_gut.title = u"The GUtenberg Title" edition_gut.subtitle = u"The GUtenberg Subtitle" edition_gut.add_contributor(bob, Contributor.AUTHOR_ROLE) work = self._work(presentation_edition=edition_git) for p in pool_gut, pool_std_ebooks: work.license_pools.append(p) work.calculate_presentation() return (work, pool_std_ebooks, pool_git, pool_gut, edition_std_ebooks, edition_git, edition_gut, alice, bob)
def add_contributors(repo, num_layers_to_crawl=0): """Add all contributors of repo to db.""" contributors = repo.get_contributors() # num_contributors = repo.contributors_count num_users = 0 count = 0 # msg = "Adding contributors: "#.format(num_contributors) for contributor in contributors: count += 1 if (num_users > config.MAX_CRAWL_COUNT_NEW or count > config.MAX_CRAWL_COUNT_TOTAL): break # If contributor is in db, skip and continue. # TODO: Consider checking last_crawled of contributor.repo/contributor.user. this_contributor = Contributor.query.filter_by( repo_id=repo.id, user_id=contributor.id).first() if this_contributor: #TODO: A queue might be more robust than a recursive process. if num_layers_to_crawl: crawl_from_user_to_repos(user, num_layers_to_crawl) continue num_users += add_user(contributor, num_layers_to_crawl) this_contributor = Contributor(repo_id=repo.id, user_id=contributor.id) db.session.add(this_contributor) db.session.commit() return num_users
def test_to_edition_sets_sort_author_name_if_obvious(self): [contributor], ignore = Contributor.lookup(self._db, u"Hawkins, Paula") contributor.display_name = u"Paula Hawkins" title = NYTBestSellerListTitle(self.one_list_title) edition = title.to_edition(self._db, self.metadata_client) eq_(contributor.sort_name, edition.sort_author) eq_(contributor.display_name, edition.author) assert edition.permanent_work_id is not None
def _sample_ecosystem(self): """ Creates an ecosystem of some sample work, pool, edition, and author objects that all know each other. """ # make some authors [bob], ignore = Contributor.lookup(self._db, u"Bitshifter, Bob") bob.family_name, bob.display_name = bob.default_names() [alice], ignore = Contributor.lookup(self._db, u"Adder, Alice") alice.family_name, alice.display_name = alice.default_names() edition_std_ebooks, pool_std_ebooks = self._edition(DataSource.STANDARD_EBOOKS, Identifier.URI, with_license_pool=True, with_open_access_download=True, authors=[]) edition_std_ebooks.title = u"The Standard Ebooks Title" edition_std_ebooks.subtitle = u"The Standard Ebooks Subtitle" edition_std_ebooks.add_contributor(alice, Contributor.AUTHOR_ROLE) edition_git, pool_git = self._edition(DataSource.PROJECT_GITENBERG, Identifier.GUTENBERG_ID, with_license_pool=True, with_open_access_download=True, authors=[]) edition_git.title = u"The GItenberg Title" edition_git.subtitle = u"The GItenberg Subtitle" edition_git.add_contributor(bob, Contributor.AUTHOR_ROLE) edition_git.add_contributor(alice, Contributor.AUTHOR_ROLE) edition_gut, pool_gut = self._edition(DataSource.GUTENBERG, Identifier.GUTENBERG_ID, with_license_pool=True, with_open_access_download=True, authors=[]) edition_gut.title = u"The GUtenberg Title" edition_gut.subtitle = u"The GUtenberg Subtitle" edition_gut.add_contributor(bob, Contributor.AUTHOR_ROLE) work = self._work(presentation_edition=edition_git) for p in pool_gut, pool_std_ebooks: work.license_pools.append(p) work.calculate_presentation() return (work, pool_std_ebooks, pool_git, pool_gut, edition_std_ebooks, edition_git, edition_gut, alice, bob)
def get(self): message = '''<h1>List of Contributors</h1> <p>This lists all Contributors currently in the distribution system as of %s.</p> <table class="sortable" border=\"1\">''' % datetime.datetime.utcnow().isoformat(' ') message += '<tr><th>Row</th><th>Contributor</th><th>Key</th></tr><br />\n' query = Contributor.gql("") dists = [] for record in query: s = '<td>%s</td><td>%s</td>\n' % (record.avname, record.avkey) if (s in dists) == False: dists += [s] for i in range(0,len(dists)): message += '<tr><td>%d</td>%s' % (i+1, dists[i]) message += "</table>" self.response.out.write((head % 'Contributor List') + message + end)
def get(self): message = '''<h1>List of Contributors</h1> <p>This lists all Contributors currently in the distribution system as of %s.</p> <table class="sortable" border=\"1\">''' % datetime.datetime.utcnow( ).isoformat(' ') message += '<tr><th>Row</th><th>Contributor</th><th>Key</th></tr><br />\n' query = Contributor.gql("") dists = [] for record in query: s = '<td>%s</td><td>%s</td>\n' % (record.avname, record.avkey) if (s in dists) == False: dists += [s] for i in range(0, len(dists)): message += '<tr><td>%d</td>%s' % (i + 1, dists[i]) message += "</table>" self.response.out.write((head % 'Contributor List') + message + end)
def Contributor_authorized(av): #True if av is on the authorized distributor list, else False token = "contr_auth_%s" % av memrecord = memcache.get(token) if memrecord is None: #dist is not in memcache, check db dbrecord = Contributor.gql('WHERE avkey = :1', av).get() if dbrecord is None: memcache.set(token, False) return False else: memcache.set(token, True) return True else: #dist is in memcache. check value if memrecord: return True else: return False
def example_data(): """Create example data for the test database.""" Dislike.query.delete() Stargazer.query.delete() Watcher.query.delete() Follower.query.delete() Contributor.query.delete() RepoLanguage.query.delete() Language.query.delete() Repo.query.delete() Account.query.delete() User.query.delete() jane = User(user_id="1", login="******", name="Jane", last_crawled=datetime.datetime.now(), last_crawled_depth=2) alex = User(user_id="2", login="******", name="Alex", last_crawled=(datetime.datetime.now() - datetime.timedelta(weeks=6)), last_crawled_depth=2) kelly = User(user_id="3", login="******", name="Kelly") db.session.add_all([jane, alex, kelly]) db.session.commit() jane_account = Account(user_id="1", access_token="abc123") db.session.add(jane_account) db.session.commit() py_repo = Repo(repo_id="1", name="python-repo", description="A Python repository", owner_id="1", last_crawled=datetime.datetime.now(), last_crawled_depth=2, url="https://github.com/jhacks/python-repo", stargazers_count=2) js_repo = Repo(repo_id="2", name="js-repo", description="A Javascript repository", owner_id="1", last_crawled=(datetime.datetime.now() - datetime.timedelta(weeks=6)), last_crawled_depth=1, url="https://github.com/jhacks/js-repo", stargazers_count=1) db.session.add_all([py_repo, js_repo]) db.session.commit() astar = Stargazer(repo_id="1", user_id="2") kstar = Stargazer(repo_id="1", user_id="3") kstar_js = Stargazer(repo_id="2", user_id="3") a_dislike_js = Dislike(repo_id="2", user_id="2") # k_dislike_js = Dislike(repo_id="2", user_id="3") db.session.add_all([astar, kstar, kstar_js, a_dislike_js]) db.session.commit() kwatch = Watcher(repo_id="1", user_id="3") a_j_follow = Follower(user_id="1", follower_id="2") k_j_follow = Follower(user_id="1", follower_id="3") j_a_follow = Follower(user_id="2", follower_id="1") db.session.add_all([kwatch, a_j_follow, k_j_follow, j_a_follow]) db.session.commit() jcon = Contributor(repo_id="1", user_id="1") kcon = Contributor(repo_id="1", user_id="3") db.session.add_all([jcon, kcon]) db.session.commit() # python = Topic(topic_id="1", topic_name="python") # api = Topic(topic_id="2", topic_name="api") # db.session.add_all([python, api]) # db.session.commit() # py_rep1 = RepoTopic(topic_id="1", repo_id="1") # api_rep1 = RepoTopic(topic_id="2", repo_id="1") # db.session.add_all([py_rep1, api_rep1]) # db.session.commit() py_lang = Language(language_id="1", language_name="python") c_lang = Language(language_id="2", language_name="c") db.session.add_all([py_lang, c_lang]) db.session.commit() py_lang_rep1 = RepoLanguage(language_id="1", repo_id="1", language_bytes=5000) c_lang_rep1 = RepoLanguage(language_id="2", repo_id="1", language_bytes=100) db.session.add_all([py_lang_rep1, c_lang_rep1]) db.session.commit()
def Contributor_delete(av, name): record = Contributor.gql('WHERE avkey = :1', av).get() if record is not None: record.delete() token = "contr_auth_%s" % av memcache.delete(token)