# Path: database.py
# def init_db():


import os
import csv
import sys
import time
import json
import shutil
import codecs
import hashlib
import StringIO
import utils
import settings
from datetime import datetime
from collections import namedtuple
from jinja2 import Environment, PackageLoader, select_autoescape, Template
from models import *
from database import db_session, init_db
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, unicode_literals


def initdb():
    key = int(time.time()) // 60
    key = hashlib.md5(str(key)).hexdigest()[:6]
    if len(sys.argv) != 3 or sys.argv[2] != key:
        print('please run the following command within the current minute')
        print('    ./maintenance.py initdb %s' % key)
        sys.exit(1)
    print('initializing the database')
    init_db()
    print('done!')


def add_compiler():
    if len(sys.argv) != 4:
        print('usage: ./maintenance.py add_compiler <student> <repo_url>')
        sys.exit(1)
    student = sys.argv[2].decode('utf-8')
    repo_url = sys.argv[3]
    c = Compiler(student=student, repo_url=repo_url)

# Path: database.py
# def init_db():


# Path: maintenance.py
import os
import csv
import sys
import time
import json
import shutil
import codecs
import hashlib
import StringIO
import utils
import settings
from datetime import datetime
from collections import namedtuple
from jinja2 import Environment, PackageLoader, select_autoescape, Template
from models import *
from database import db_session, init_db

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function, division, unicode_literals


def initdb():
    key = int(time.time()) // 60
    key = hashlib.md5(str(key)).hexdigest()[:6]
    if len(sys.argv) != 3 or sys.argv[2] != key:
        print('please run the following command within the current minute')
        print('    ./maintenance.py initdb %s' % key)
        sys.exit(1)
    print('initializing the database')
    init_db()
    print('done!')


def add_compiler():
    if len(sys.argv) != 4:
        print('usage: ./maintenance.py add_compiler <student> <repo_url>')
        sys.exit(1)
    student = sys.argv[2].decode('utf-8')
    repo_url = sys.argv[3]
    c = Compiler(student=student, repo_url=repo_url)

    db_session.add(c)