Пример #1
0
    def get_session_stats():
        plugin = JBPluginDB.jbox_get_plugin(JBPluginDB.JBP_USAGE_ACCOUNTING)
        if plugin is None:
            return None

        today = datetime.now()
        week_dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
        today_dates = [today]
        stats = {
            'day': plugin.get_stats(today_dates),
            'week': plugin.get_stats(week_dates)
        }
        return stats
Пример #2
0

def table_create(table_name, columns, keys=None):
    allcolumns = columns if keys is None else keys + columns
    sql = 'create table %s (%s' % (table_name, ', '.join(allcolumns))
    if keys is not None:
        sql += (', primary key (%s)' % (', '.join(keys), ))
    sql += ')'
    c.execute(sql)
    conn.commit()


print("connecting to %s" % (sys.argv[1], ))
conn = sqlite3.connect(sys.argv[1])
c = conn.cursor()

tables = [
    JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps,
    JBoxAPISpec, JBoxUserProfile
]
for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE_RDBMS):
    tables.append(plugin)

for cls in tables:
    print("Creating %s..." % (cls.NAME, ))
    if table_exists(cls.NAME):
        print("\texists already!")
    else:
        table_create(cls.NAME, cls.ATTRIBUTES, cls.KEYS)
        print("\tcreated.")
Пример #3
0
        c.fetchall()
        return c.description is not None
    except:
        return False


def table_create(table_name, columns, keys=None):
    allcolumns = columns if keys is None else keys + columns
    sql = 'create table %s (%s' % (table_name, ', '.join(allcolumns))
    if keys is not None:
        sql += (', primary key (%s)' % (', '.join(keys),))
    sql += ')'
    c.execute(sql)
    conn.commit()

print("connecting to %s" % (sys.argv[1],))
conn = sqlite3.connect(sys.argv[1])
c = conn.cursor()

tables = [JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxAPISpec]
for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE_RDBMS):
    tables.append(plugin)

for cls in tables:
    print("Creating %s..." % (cls.NAME,))
    if table_exists(cls.NAME):
        print("\texists already!")
    else:
        table_create(cls.NAME, cls.ATTRIBUTES, cls.KEYS)
        print("\tcreated.")
    unix_socket = db['unix_socket']
    db = db['db']
    return MySQLdb.connect(user=user,
                           passwd=passwd,
                           db=db,
                           unix_socket=unix_socket)


conn = get_connection()
c = conn.cursor()

tables = [
    JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps,
    JBoxAPISpec, JBoxUserProfile
]
for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE_DYNAMODB):
    tables.append(plugin)

for cls in tables:
    print("Creating %s..." % (cls.NAME, ))
    if table_exists(cls.NAME):
        print("\texists already!")
    else:
        table_create(cls.NAME, cls.ATTRIBUTES, cls.TYPES, cls.KEYS,
                     cls.KEYS_TYPES)
        print("\tcreated.")

for cls in tables:
    print("Creating indexes for %s..." % (cls.NAME))
    indexes_create(cls.NAME, cls.SQL_INDEXES)
Пример #5
0
from juliabox.db import JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps, JBPluginDB, JBoxAPISpec, JBoxUserProfile

# import any plugins that contribute tables
import juliabox.plugins.course_homework
import juliabox.plugins.usage_accounting
import juliabox.plugins.vol_ebs


def table_exists(name):
    t = Table(name)
    try:
        t.describe()
        return True
    except:
        return False

tables = [JBoxUserV2, JBoxDynConfig, JBoxSessionProps, JBoxInstanceProps, JBoxAPISpec, JBoxUserProfile]
for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE_DYNAMODB):
    tables.append(plugin)

for cls in tables:
    print("Creating %s..." % (cls.NAME,))
    if table_exists(cls.NAME):
        print("\texists already!")
    else:
        Table.create(cls.NAME, schema=cls.SCHEMA, indexes=cls.INDEXES, global_indexes=cls.GLOBAL_INDEXES, throughput={
            'read': 1,
            'write': 1
        })
        print("\tcreated.")
Пример #6
0
 def _get_db_plugin():
     if not CompGCE.DB_PLUGIN:
         CompGCE.DB_PLUGIN = JBPluginDB.jbox_get_plugin(JBPluginDB.JBP_DB_CLOUDSQL)
     return CompGCE.DB_PLUGIN
Пример #7
0
 def _get_db_plugin():
     if not CompGCE.DB_PLUGIN:
         CompGCE.DB_PLUGIN = JBPluginDB.jbox_get_plugin(
             JBPluginDB.JBP_DB_CLOUDSQL)
     return CompGCE.DB_PLUGIN
Пример #8
0
 def record_usage(self):
     plugin = JBPluginDB.jbox_get_plugin(JBPluginDB.JBP_USAGE_ACCOUNTING)
     if plugin is not None:
         plugin.record_session_time(self.get_name(), self.get_image_names(), self.time_created(), self.time_finished())
Пример #9
0
 def record_usage(self):
     plugin = JBPluginDB.jbox_get_plugin(JBPluginDB.JBP_USAGE_ACCOUNTING)
     if plugin is not None:
         plugin.record_session_time(self.get_name(), self.get_image_names(),
                                    self.time_created(),
                                    self.time_finished())
Пример #10
0
 def _get_db_plugin():
     if not JBoxSMTP.DB_PLUGIN:
         JBoxSMTP.DB_PLUGIN = JBPluginDB.jbox_get_plugin(
             JBPluginDB.JBP_DB_CLOUDSQL)
     return JBoxSMTP.DB_PLUGIN
Пример #11
0
 def _get_db_plugin():
     if not JBoxSMTP.DB_PLUGIN:
         JBoxSMTP.DB_PLUGIN = JBPluginDB.jbox_get_plugin(JBPluginDB.JBP_DB_CLOUDSQL)
     return JBoxSMTP.DB_PLUGIN