Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
cli = BundleCLI(CodaLabManager())
try:
cli.do_command(sys.argv[1:])
except KeyboardInterrupt:
print('Terminated by Ctrl-C')
sys.exit(130)
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
manager = CodaLabManager()
engine = manager.model().engine
connection = engine.connect()
context.configure(
connection=connection,
target_metadata=target_metadata
)
try:
with context.begin_transaction():
context.run_migrations()
finally:
connection.close()
def _create_cli(self, worksheet_uuid):
manager = CodaLabManager(temporary=True, clients={settings.BUNDLE_SERVICE_URL: self.client})
manager.set_current_worksheet_uuid(self.client, worksheet_uuid)
cli = bundle_cli.BundleCLI(manager, headless=True)
return cli
def _create_cli(self, worksheet_uuid):
"""
Create an instance of the CLI.
The CLI uses JsonApiClient to communicate back to the REST API.
This is admittedly not ideal since now the REST API is essentially
making HTTP requests back to itself. Future potential solutions might
include creating a subclass of JsonApiClient that can reroute HTTP
requests directly to the appropriate Bottle view functions.
"""
output_buffer = StringIO()
rest_client = JsonApiClient(self._rest_url(), lambda: get_user_token())
manager = CodaLabManager(
temporary=True,
config=local.config,
clients={
self._rest_url(): rest_client
})
manager.set_current_worksheet_uuid(self._rest_url(), worksheet_uuid)
cli = bundle_cli.BundleCLI(manager, headless=True, stdout=output_buffer, stderr=output_buffer)
return cli, output_buffer
def main(args):
manager = CodaLabManager()
model = manager.model()
# Get the the message
subject = args.subject
with open(args.body_file) as f:
body_template = f.read()
mime_type = 'html' if args.body_file.endswith('.html') else 'plain'
# Figure out who we want to send
to_send_list = get_to_send_list(model, args.threshold)
sent_list = get_sent_list(args.sent_file)
sent_emails = set(info['email'] for info in sent_list)
pending_to_send_list = [info for info in to_send_list if info['email'] not in sent_emails]
print('Already sent %d emails, %d to go' % (len(sent_list), len(pending_to_send_list)))
for i, info in enumerate(pending_to_send_list):
#!./venv/bin/python
"""
Script that creates the default CodaLab OAuth2 clients.
- codalab_cli_client for the Bundle CLI clients authenticating through the Password Grant
- codalab_worker_client for workers authenticating through the Password Grant
TODO(skoo): Create row for the web client given a redirect url.
"""
import sys
sys.path.append('.')
from codalab.lib.codalab_manager import CodaLabManager
from codalab.objects.oauth2 import OAuth2Client
manager = CodaLabManager()
model = manager.model()
if not model.get_oauth2_client('codalab_cli_client'):
model.save_oauth2_client(OAuth2Client(
model,
client_id='codalab_cli_client',
secret=None,
name='Codalab CLI',
user_id=None,
grant_type='password',
response_type='token',
scopes='default',
redirect_uris='',
))
if not model.get_oauth2_client('codalab_worker_client'):
def __str__(self):
return (
"""
This was a dry run, no migration occurred. To perform full migration,
run again with `-f':
%s -f
""".rstrip()
% sys.argv[0]
)
dry_run = False if len(sys.argv) > 1 and sys.argv[1] == '-f' else True
manager = CodaLabManager()
model = manager.model()
CODALAB_HOME = manager.codalab_home
# Turn on query logging
model.engine.echo = True
###############################################################
# Configure connection to Django database
###############################################################
django_config = read_json_or_die(os.path.join(CODALAB_HOME, 'website-config.json'))
# Use default settings as defined in codalab-worksheets
if 'database' not in django_config:
django_config['database'] = {'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'codalab.sqlite3'}
def create_cli(worksheet_uuid):
"""
Create an instance of the CLI.
The CLI uses JsonApiClient to communicate back to the REST API.
This is admittedly not ideal since now the REST API is essentially
making HTTP requests back to itself. Future potential solutions might
include creating a subclass of JsonApiClient that can reroute HTTP
requests directly to the appropriate Bottle view functions.
"""
output_buffer = StringIO()
rest_client = JsonApiClient(rest_url(), get_user_token)
manager = CodaLabManager(
temporary=True,
config=local.config,
clients={
rest_url(): rest_client
})
manager.set_current_worksheet_uuid(rest_url(), worksheet_uuid)
cli = bundle_cli.BundleCLI(manager, headless=True, stdout=output_buffer, stderr=output_buffer)
return cli, output_buffer
"""
import os
import sys
import shlex
from subprocess import Popen
from functools import reduce
sys.path.append('.')
from codalab.lib.codalab_manager import CodaLabManager
from codalab.lib import path_util
dry_run = False if len(sys.argv) > 1 and sys.argv[1] == '-f' else True
manager = CodaLabManager()
model = manager.model()
CODALAB_HOME = manager.codalab_home
"""Move data/ directory over to a temp area, and create a staging tree for uuid-based storage"""
DATA_DIR = os.path.join(CODALAB_HOME, 'data')
FINAL_LOCATION = os.path.join(CODALAB_HOME, 'bundles')
if not dry_run:
path_util.make_directory(FINAL_LOCATION)
"""For each data hash, get a list of all bundles that have that hash, and make a copy of the bundle in the staging
area under the UUID for the bundle."""
data_hashes = reduce(lambda x, y: x + y, path_util.ls(DATA_DIR))
for data_hash in data_hashes:
orig_location = os.path.join(DATA_DIR, data_hash)