Ejemplo n.º 1
0
def which(args):
    from balsam.django_config.db_index import refresh_db_index
    from balsam.django_config.serverinfo import ServerInfo
    import pprint

    if args.list:
        pprint.pprint(refresh_db_index())
    elif args.name:
        db_list = refresh_db_index()

        # Try exact match first
        name = os.path.abspath(os.path.expanduser(args.name))
        if name in db_list:
            print(name)
            sys.exit(0)

        matches = [db for db in db_list if args.name in db]
        if len(matches) == 0:
            sys.stderr.write(f"No DB matching {args.name} is cached\n\n")
            sys.exit(1)
        elif len(matches) > 1:
            sys.stderr.write(
                f"DB name {args.name} is too ambiguous; multiple matches\n"
                "Please give a longer unique substring\n\n")
            sys.exit(1)
        else:
            print(matches[0])
            sys.exit(0)
    else:
        db_path = os.environ.get('BALSAM_DB_PATH')
        if db_path:
            print("Current Balsam DB:", db_path)
            dat = ServerInfo(os.environ['BALSAM_DB_PATH']).data
            pprint.pprint(dat)
        else:
            print("BALSAM_DB_PATH is not set")
            print(
                'Use "source balsamactivate" to activate one of these existing databases:'
            )
            pprint.pprint(refresh_db_index())
Ejemplo n.º 2
0
        j = BalsamJob()
        j.save()
        j.delete()
    except:
        print("BalsamJob table not properly created")
        raise
    else:
        print("BalsamJob table created successfully")


if __name__ == "__main__":
    if not check_postgres():
        raise RuntimeError(POSTGRES_MSG)

    dbpath = sys.argv[1]
    os.environ['BALSAM_DB_PATH'] = dbpath
    serverInfo = ServerInfo(dbpath)

    postgres_init(serverInfo)
    run_migrations()
    connection.close()
    postgres_control.kill_server(serverInfo)

    base = dbpath[:-1] if dbpath[-1] == '/' else dbpath
    basename = os.path.basename(base)
    msg = f"  Successfully created Balsam DB at: {os.environ['BALSAM_DB_PATH']}  "
    print('\n' + '*' * len(msg))
    print(msg)
    print(f"  Use `source balsamactivate {basename}` to begin working.")
    print('*' * len(msg) + '\n')
Ejemplo n.º 3
0
        sys.exit(1)
    os.environ['BALSAM_DB_PATH'] = path
    return path


if os.environ.get('BALSAM_SPHINX_DOC_BUILD_ONLY', False):
    tempdir = tempfile.TemporaryDirectory()
    BALSAM_PATH = tempdir.name
    print(
        "detected env BALSAM_SPHINX_DOC_BUILD_ONLY: will not connect to a real DB"
    )
else:
    BALSAM_PATH = resolve_db_path()

bootstrap()
DATABASES = ServerInfo(BALSAM_PATH).django_db_config()

# SUBDIRECTORY SETUP
# ------------------
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LOGGING_DIRECTORY = os.path.join(BALSAM_PATH, 'log')
DATA_PATH = os.path.join(BALSAM_PATH, 'data')
SERVICE_PATH = os.path.join(BALSAM_PATH, 'qsubmit')
BALSAM_WORK_DIRECTORY = DATA_PATH

for d in [BALSAM_PATH, DATA_PATH, LOGGING_DIRECTORY, SERVICE_PATH]:
    if not os.path.exists(d):
        os.makedirs(d)

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=gyp#o9ac0@w3&-^@a)j&f#_n-o=k%z2=g5u@z5+klmh_*hebj'