Beispiel #1
0
def create_tables():
  database.connect()
  Category.drop_table(fail_silently=True)
  Thread.drop_table(fail_silently=True)
  Post.drop_table(fail_silently=True)
  Role.drop_table(fail_silently=True)
  Profile.drop_table(fail_silently=True)
  database.create_tables([Category, Thread, Post, Profile, Role])
  database.close()

  if settings.DEBUG:
    setup_temp_data()
Beispiel #2
0
    file_type = CharField(default='image')
    file_orgin_name = CharField(null=True)
    file_ext = CharField(default='jpg')
    file_hash = CharField(unique=True)
    img_hash = CharField(null=True)

    width = IntegerField(null=True)
    height = IntegerField(null=True)

    orientation = IntegerField(null=True)
    make = CharField(null=True)
    model = CharField(null=True)
    location = CharField(null=True)

    class Meta:
        db_table = 'photos'


class ConflictPhoto(MySQLModel):
    # TODO, implement this
    exist_photo = ForeignKeyField(Photo, related_name='conflict_photos')

    class Meta:
        db_table = 'conflict_photos'


try:
    database.create_tables([Photo])
except InternalError:
    pass
Beispiel #3
0
    def got_coords(self, coords_list):
        for coords in coords_list:
            self.print_state('node', coords[0])
            changelib.store_node_coords_fast(coords[0], coords[2], coords[1])

    def got_way(self, ways):
        for way in ways:
            self.print_state('way', way[0])
            changelib.update_way_nodes(way[0], way[2])

    def got_relation(self, relations):
        for rel in relations:
            self.print_state('relation', rel[0])
            members = [x[1][0] + str(x[0]) for x in rel[2]]
            changelib.update_relation_members(rel[0], members)


database.connect()
database.create_tables([NodeRef, WayRelRef, Members], safe=True)
changelib.CACHE = False
changelib.open(path)
p = ParserForChange()
op = OSMParser(concurrency=1,
               coords_callback=p.got_coords,
               ways_callback=p.got_way,
               relations_callback=p.got_relation)
op.parse(sys.argv[1])
print
changelib.close()
Beispiel #4
0
def setup_db():
    database.create_tables()
Beispiel #5
0
        sys.stdout.write('\rProcessing {0} {1:.1f}m{2}'.format(typ, ident / 1000000.0, ' ' * 10))
        sys.stdout.flush()
        self.flush()

    def got_coords(self, coords_list):
        for coords in coords_list:
            self.print_state('node', coords[0])
            changelib.store_node_coords_fast(coords[0], coords[2], coords[1])

    def got_way(self, ways):
        for way in ways:
            self.print_state('way', way[0])
            changelib.update_way_nodes(way[0], way[2])

    def got_relation(self, relations):
        for rel in relations:
            self.print_state('relation', rel[0])
            members = [x[1][0] + str(x[0]) for x in rel[2]]
            changelib.update_relation_members(rel[0], members)

database.connect()
database.create_tables([NodeRef, WayRelRef, Members], safe=True)
changelib.CACHE = False
changelib.open(path)
p = ParserForChange()
op = OSMParser(concurrency=1, coords_callback=p.got_coords,
               ways_callback=p.got_way, relations_callback=p.got_relation)
op.parse(sys.argv[1])
print
changelib.close()
Beispiel #6
0
from db import database
from models import SentinelScene

# Create table in a database

database.connect()
database.create_tables([SentinelScene])
Beispiel #7
0
def parse_state(s):
    if s.isdigit():
        return int(s)
    m = re.search(r'\.org/replication.*/(\d{3})/(\d{3})/(\d{3})\.', s)
    if m:
        return int(m.group(1) + m.group(2) + m.group(3))
    return 0

if len(sys.argv) < 3:
    print 'Set state values for changechange.'
    print 'Usage: {0} <changeset_state> <replication_state> [path_to_db]'.format(sys.argv[0])
    sys.exit(1)

changeset = parse_state(sys.argv[1])
replication = parse_state(sys.argv[2])
if changeset < 1800000 or replication < 1800000:
    print 'Too old replication values:', changeset, replication
    sys.exit(1)

path = os.path.dirname(sys.argv[0]) if len(sys.argv) < 4 else sys.argv[3]
database.init(os.path.join(path, 'changechange.db'))
database.connect()
database.create_tables([State], safe=True)
try:
    st = State.get(State.id == 1)
except State.DoesNotExist:
    st = State()
st.changeset = changeset
st.replication = replication
st.save()
Beispiel #8
0
            raise TypeError('%s should be subclass of baseModel' % appModel)


if __name__ == '__main__':
    import os
    from conf import ENVIRONMENT_VARIABLE
    # refer the setting modules
    os.environ[ENVIRONMENT_VARIABLE] = 'setting'
    print os.getcwd()

    finder = modelFinder()
    print finder.getInstalledModel()

    # create all table
    from db import database

    database.connect()

    for app, modelList in finder.getInstalledModel():
        print app, modelList
        for name, model in modelList:
            print name
            try:
                database.create_tables([model])
                # print app+' @ '+ name
            except Exception as e:
                print e
            finally:
                testFiledFinder = fieldFinder()
                testFiledFinder.getAllField(model)
    database.close()
Beispiel #9
0
def initialize():
    database.create_tables([User, PageView, Site, SiteUser], safe=True)
Beispiel #10
0
from contrib.admin.appModel import modelFinder
from db import database

import sys

if len(sys.argv) != 2:
    print('''Only one argv is supported''')
else:
    if sys.argv[1] == 'migrate':
        modelsFinder = modelFinder()
        # a tuple containing three element : app,className,class
        modelsList = modelsFinder.getInstalledModel()
        models = [model for name,package in modelsList for dname,model in package if model!= []]
        print 'These models are searched : ', models
        print database.create_tables(models,safe=True)
    elif sys.argv[1] == 'createsuperuser':
        from db import database
        from contrib.admin.models import admin

        database.connect()
        try:
            database.create_tables([admin])
        except:
            pass
        print '''  TJANGO Create administrator '''

        username = raw_input('Please input your username : '******'Please input your password : ')
        new_adminUser = admin(username=username, password=password,isStaff=True,isAdmin=True)
        new_adminUser.save()
Beispiel #11
0
        osc = changes_to_osc(changes, changeset_id)
        resp = requests.post('{0}/api/0.6/changeset/{1}/upload'.format(API_ENDPOINT, changeset_id), osc, auth=oauth)
        if resp.status_code == 200:
            task.status = 'done'
            task.error = str(changeset_id)
        else:
            # We don't want to exit before closing the changeset
            task.status = 'error'
            task.error = 'Server rejected the changeset with code {0}: {1}'.format(resp.code, resp.text)
        task.save()
    finally:
        resp = requests.put('{0}/api/0.6/changeset/{1}/close'.format(API_ENDPOINT, changeset_id), auth=oauth)


if __name__ == '__main__':
    if not lock():
        sys.exit(0)

    database.connect()
    database.create_tables([Task], safe=True)
    try:
        task = Task.get(Task.pending)
    except Task.DoesNotExist:
        # Yay, no jobs for us.
        sys.exit(0)

    try:
        process(task)
    except Exception as e:
        update_status_exit_on_error(task, 'system error', str(e))
Beispiel #12
0
parser_start.add_argument('--port', metavar='PORTA', type=int,
                          help='porta para execução (padrão: 9000)',
                          default='9000')
parser_syncdb = subparsers.add_parser('syncdb', help='cria tabelas do banco de dados')
parser_syncdb.set_defaults(cmd='syncdb')
parser_createuser = subparsers.add_parser('createuser', help='cria usuário')
parser_createuser.add_argument('username', metavar='USUÁRIO', type=str,
                               help='nome de usuário')
parser_createuser.add_argument('password', metavar='SENHA', type=str,
                               help='senha do usuário')
parser_createuser.set_defaults(cmd='createuser')
args = parser.parse_args()

if args.cmd == 'start':
    if not os.path.exists(args.directory) or not os.path.isdir(args.directory):
        parser.error("diretório para sincronização inexistente")
    start_server(args.directory, args.host, args.port)
elif args.cmd == 'syncdb':
    database.connect()
    print('Criando tabelas ...')
    database.create_tables(__all__)
    print('Executando migrações ...')
    migrations.createuser_system()
    print('Pronto')
elif args.cmd == 'createuser':
    User.create(
        username=args.username,
        password=args.password,
    )
    print('Usuário criado com sucesso.')