Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify source in config #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions montage/rdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,7 @@ def activate_round(self, round_id):

def add_entries_from_cat(self, round_id, cat_name):
rnd = self.user_dao.get_round(round_id)
if ENV_NAME == 'dev':
source = 'remote'
else:
source = 'local'
entries = loaders.load_category(cat_name, source=source)
entries = loaders.load_category(cat_name, source=get_source())
entries, new_entry_count = self.add_entries(rnd, entries)

msg = ('%s loaded %s entries from category (%s), %s new entries added'
Expand All @@ -1541,11 +1537,7 @@ def add_entries_from_cat(self, round_id, cat_name):

def add_entries_by_name(self, round_id, file_names):
rnd = self.user_dao.get_round(round_id)
if ENV_NAME == 'dev':
source = 'remote'
else:
source = 'local'
entries = loaders.load_by_filename(file_names, source=source)
entries = loaders.load_by_filename(file_names, source=get_source())
entries, new_entry_count = self.add_entries(rnd, entries)

msg = ('%s loaded %s entries from filenames, %s new entries added'
Expand All @@ -1558,13 +1550,9 @@ def add_entries_from_csv(self, round_id, csv_url):
# NOTE: this no longer creates RoundEntries, use
# add_round_entries to do this.
rnd = self.user_dao.get_round(round_id)
if ENV_NAME == 'dev':
source = 'remote'
else:
source = 'local'
try:
entries, warnings = loaders.get_entries_from_csv(csv_url,
source=source)
source=get_source())
except ValueError as e:
raise InvalidAction('unable to load csv "%s"' % csv_url)

Expand Down Expand Up @@ -3097,6 +3085,23 @@ def choose_eligible(eligible_users):
'task_count_mean': mean(vote_count_map.values())}


def get_source():
from utils import load_env_config

config = load_env_config()

config_source = config.get('source')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source is a little vague here, can we call it commons_source?

An aside: remote and local are pretty bad names, too, I'll take the full blame. The proper meaning, maybe worth a comment: remote = toolforge util service (ideal name: tools_api), local = toolforge commons db replica (ideal name: db_replica).

if config_source:
return config_source

if ENV_NAME == 'dev':
source = 'remote'
else:
source = 'local'

return source


def make_rdb_session(echo=True):
from utils import load_env_config
from sqlalchemy import create_engine
Expand Down