Ejemplo n.º 1
0
def get_IRM_report_data_set(input_file, sheet_name):
    print("Reading from file {}...".format(input_file))
    data_book = Databook().load('xlsx', open(input_file, 'rb').read())
    sheets = data_book.sheets()
    try:
        return next(data_set for data_set in sheets
                    if data_set.title.strip() == sheet_name)
    except StopIteration:
        sys.exit('Sheet not found in xlsx file.')
Ejemplo n.º 2
0
def gen_xls_data(book_name, sheet_name):
    book_name += '.xls'
    book_path = HOMEPATH/'xls_case'/book_name
    book = Databook().load('xls', open(str(book_path), 'rb').read())
    for sheet in book.sheets():
        if sheet.title == sheet_name:
            ret = json.loads(sheet.json)
            return map(parse, ret)
    return []
Ejemplo n.º 3
0
def gen_data(book_name, sheet_name):
    book_name += '.xls'
    sheet_name = sheet_name.partition('_')[-1]
    book_path = HOMEPATH / 'datas' / book_name
    dbook = Databook().load('xls', open(str(book_path), 'rb').read())
    for sheet in dbook.sheets():
        if sheet.title == sheet_name:
            ret = json.loads(sheet.json)
            return map(parse, ret)
    return []
Ejemplo n.º 4
0
def import_snapshot(file, irm_snapshot_id):
    data_book = Databook().load(file, "xlsx")
    dataset = data_book.sheets()[0]
    preprocessed_dataset = preprocess(dataset)
    # Ensure projects exist
    for IRM_project_id in preprocessed_dataset["Project ID"]:
        if IRM_project_id:
            models.ProvInfraProject.objects.get_or_create(
                IRM_project_id=IRM_project_id)
    if len(preprocessed_dataset) > 0:
        preprocessed_dataset.append_col([irm_snapshot_id] *
                                        len(preprocessed_dataset),
                                        header="irm_snapshot")
    resource = ProvInfraProjectSnapshotResource()
    result = resource.import_data(preprocessed_dataset)
    return result
Ejemplo n.º 5
0
def import_snapshot(snapshot):
    file = snapshot.file.read()
    data_book = Databook().load(file, "xlsx")
    dataset = data_book.sheets()[0]
    preprocessed_dataset = preprocess(dataset)

    # Ensure projects exist
    for IRM_project_id in preprocessed_dataset["Project ID"]:
        if IRM_project_id:
            models.InfraProject.objects.get_or_create(
                IRM_project_id=IRM_project_id,
                sphere_slug=snapshot.sphere.slug)

    if len(preprocessed_dataset) > 0:
        preprocessed_dataset.append_col([snapshot.id] *
                                        len(preprocessed_dataset),
                                        header="irm_snapshot")
        preprocessed_dataset.append_col([snapshot.sphere.slug] *
                                        len(preprocessed_dataset),
                                        header="sphere_slug")
    resource = InfraProjectSnapshotResource()
    result = resource.import_data(preprocessed_dataset)
    return result