Esempio n. 1
0
def dump_data():
    dir_name = 'nextgisbio/initial_data/csv/' + time.strftime("%Y_%m_%d_%H_%M_%S")

    if not os.path.exists(dir_name):
        os.makedirs(dir_name)
    else:
        raise Exception('Directory for exported csv files already exists')

    get_path_name = lambda name: os.path.join(dir_name, name)

    with transaction.manager:
        Annotation.export_to_file(get_path_name('annotation.csv'))
        Cards.export_to_file(get_path_name('cards.csv'))
        Person.export_to_file(get_path_name('person.csv'))
        Taxa_scheme.export_to_file(get_path_name('taxa_scheme.csv'))
        Museum.export_to_file(get_path_name('museum.csv'))
        Coord_type.export_to_file(get_path_name('coord_type.csv'))
        Anthr_press.export_to_file(get_path_name('anthr_press.csv'))
        Vitality.export_to_file(get_path_name('vitality.csv'))
        Abundance.export_to_file(get_path_name('abundance.csv'))
        Footprint.export_to_file(get_path_name('footprint.csv'))
        Pheno.export_to_file(get_path_name('pheno.csv'))
        Inforesources.export_to_file(get_path_name('inforesources.csv'))
        Legend.export_to_file(get_path_name('legend.csv'))
        Area_type.export_to_file(get_path_name('area_type.csv'))
        Key_area.export_to_file(get_path_name('key_area.csv'))
        RedBook.export_to_file(get_path_name('redbooks.csv'))
        User.export_to_file(get_path_name('user.csv'))
        Squares.export_to_file(get_path_name('square_karea_association.csv'))
        Taxon.export_to_file(get_path_name('taxon.csv'))
        Synonym.export_to_file(get_path_name('synonym.csv'))
        Images.export_to_file(get_path_name('images.csv'))
        CardsImages.export_to_file(get_path_name('cards_images.csv'))

    return dir_name
Esempio n. 2
0
def main(argv=sys.argv):
    if len(argv) != 2 and len(argv) != 3:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)

    md5_pass = False
    if len(argv) == 3 and argv[2] == '--md5-pass':
        md5_pass = True

    Base.metadata.drop_all(engine)
    Base.metadata.create_all(engine)

    # Заполним таблицы данными:

    # Таксоны
    taxons_file = 'nextgisbio/initial_data/csv/taxon.csv'
    Taxon.add_from_file(taxons_file)

    synonym_file = 'nextgisbio/initial_data/csv/synonym.csv'
    Synonym.add_from_file(synonym_file)

    # Справочники

    person_file = 'nextgisbio/initial_data/csv/person.csv'
    Person.add_from_file(person_file)

    taxa_file = 'nextgisbio/initial_data/csv/taxa_scheme.csv'
    Taxa_scheme.add_from_file(taxa_file)

    museum_file = 'nextgisbio/initial_data/csv/museum.csv'
    Museum.add_from_file(museum_file)

    coord_type_file = 'nextgisbio/initial_data/csv/coord_type.csv'
    Coord_type.add_from_file(coord_type_file)

    ant_file = 'nextgisbio/initial_data/csv/anthr_press.csv'
    Anthr_press.add_from_file(ant_file)

    vital_file = 'nextgisbio/initial_data/csv/vitality.csv'
    Vitality.add_from_file(vital_file)

    abundance_file = 'nextgisbio/initial_data/csv/abundance.csv'
    Abundance.add_from_file(abundance_file)

    footprint_file = 'nextgisbio/initial_data/csv/footprint.csv'
    Footprint.add_from_file(footprint_file)

    pheno_file = 'nextgisbio/initial_data/csv/pheno.csv'
    Pheno.add_from_file(pheno_file)

    infores_file = 'nextgisbio/initial_data/csv/inforesources.csv'
    Inforesources.add_from_file(infores_file)

    area_type_file = 'nextgisbio/initial_data/csv/area_type.csv'
    Area_type.add_from_file(area_type_file)

    legend_file = 'nextgisbio/initial_data/csv/legend.csv'
    Legend.add_from_file(legend_file)

    key_area_file = 'nextgisbio/initial_data/csv/key_area.csv'
    Key_area.add_from_file(key_area_file)

    # Нужно добавить шейпы и заполнить данными таблицу
    # связей (square_keyarea_association) многие-ко-многим между Squares и Key_area
    shp_file = 'nextgisbio/initial_data/shp/key_areas_25km.shp'
    association_file = 'nextgisbio/initial_data/csv/square_karea_association.csv'
    Squares.add_from_file(association_file, shp_file)

    # Карточки и аннотации
    cards_file = 'nextgisbio/initial_data/csv/cards.csv'
    Cards.add_from_file(cards_file)

    ann_file = 'nextgisbio/initial_data/csv/annotation.csv'
    Annotation.add_from_file(ann_file)

    # Пользователи
    users_file = 'nextgisbio/initial_data/csv/user.csv'
    User.add_from_file(users_file, md5_pass)

    red_books_csv = 'nextgisbio/initial_data/csv/redbooks.csv'
    RedBook.import_from_csv(red_books_csv)

    images_csv = 'nextgisbio/initial_data/csv/images.csv'
    Images.import_from_csv(images_csv)

    cards_images_csv = 'nextgisbio/initial_data/csv/cards_images.csv'
    CardsImages.import_from_csv(cards_images_csv)