示例#1
0
def main(
    dbfile,
    start_id=1,
    write_reaction=True,
    write_ase=True,
    write_publication=True,
    write_reaction_system=True,
    block_size=1000,
    start_block=0,
    db_user='******',
    db_password=None,
):

    stdout.write('Starting db2server\n')

    db = CathubPostgreSQL(user=db_user, password=db_password)
    stdout.write('Established SQL Server connection.\n')
    db.transfer(dbfile,
                start_id=start_id,
                write_reaction=write_reaction,
                write_ase=write_ase,
                write_publication=write_publication,
                write_reaction_system=write_reaction_system,
                block_size=block_size,
                start_block=start_block)
示例#2
0
def delete():
    if auth_required(f, session=flask.session):
        params = flask.request.get_json()
        endorser = params.get('userInfo', {}).get('username', '')
        endorser_email = params.get('userInfo', {}).get('email', '')
        pub_id = params.get('dataset', {}).get('pubId', '')

        cathub_db = CathubPostgreSQL(
            user='******',
            password=os.environ.get('UPLOAD_ADMIN_PASSWORD'))
        userhandle = cathub_db.get_pub_id_owner(pub_id)

        if not userhandle == endorser_email:
            return flask.jsonify({
                'status':
                'Failed',
                'message':
                "You don't have permission to delete this dataset"
            })

        cathub_db.delete_publication(pub_id)

        return flask.jsonify({
            'status':
            'ok',
            'message':
            "The dataset '{}' was succesfully deleted".format(pub_id)
        })
示例#3
0
 def test2_cli_db2server(self):
     from cathub.postgresql import CathubPostgreSQL
     from cathub.cli import db2server
     db = CathubPostgreSQL(user='******')
     con = db._connect()
     db._initialize(con)
     db.truncate_schema()
     runner = CliRunner()
     runner.invoke(db2server,
                   ['--dbuser=postgres', 'aayush/MontoyaChallenge2015.db'])
示例#4
0
    def test7_modify_reaction(self):
        db = CathubPostgreSQL(user='******')
        id = db.check(pub_id='MontoyaChallenge2015',
                      chemical_composition='Pt16',
                      reactants=json.dumps({
                          'N2gas': 0.5,
                          'star': 1.0
                      }),
                      products=json.dumps({'Nstar': 1.0}))

        db.update_reaction(id, reaction_energy=10)
        db.delete_reaction(id)
示例#5
0
    def __init__(self, user='******', filename=None):

        if filename is not None:
            sql_url = 'sqlite:///' + str(filename)
            self.backend = 'sqlite'
        else:
            sql_url = CathubPostgreSQL(user).server_name
            self.backend = 'postgres'

        self.sql_url = sql_url

        self.connection = None
示例#6
0
    def test3_upload(self):
        """Ensure postgres database is empty"""
        db = CathubPostgreSQL(user='******')
        con = db._connect()
        db._initialize(con)
        db.truncate_schema()
        con.commit()
        con.close()

        db2server.main(
            '{path}/aayush/MontoyaChallenge2015.db'.format(path=path),
            user='******')
        if os.path.exists(
                '{path}/aayush/MontoyaChallenge2015.db'.format(path=path)):
            os.remove(
                '{path}/aayush/MontoyaChallenge2015.db'.format(path=path))
示例#7
0
def main():
    server_name = CathubPostgreSQL().server_name
    db = ase.db.connect(server_name)
    return db
示例#8
0
 def test6_delete_user(self):
     db = CathubPostgreSQL(user='******')
     db.delete_user('viggo')
示例#9
0
 def test5_release(self):
     with CathubPostgreSQL(user='******') as db:
         db.release(['MontoyaChallenge2015'],
                    from_schema='public',
                    to_schema='viggo')
示例#10
0
 def test4_create_user(self):
     with CathubPostgreSQL(user='******') as db:
         db.create_user('viggo', row_limit=None)
示例#11
0
def get_ase_db():
    server_name = CathubPostgreSQL().server_name
    return ase.db.connect(server_name)