Ejemplo n.º 1
0
        "SERVERCFG",
        nargs="?",
        default="DEFAULT",
        help=
        "Name of the server configuration section e.g. 'production' or 'testing'. Edit archivesspace.cfg to add a server configuration section. If no configuration is specified, the default settings will be used host=localhost user=admin pass=admin."
    )
    argparser.add_argument(
        "CSVname",
        nargs="?",
        default="DEFAULT",
        help=
        "Name of the CSV spreadsheet, e.g, 'duplaix.csv. Note: It must be in the same directory as this code file."
    )
    cliArguments = argparser.parse_args()

    aspace = archivesspace.ArchivesSpace()
    aspace.setServerCfg(CONFIGFILE, section=cliArguments.SERVERCFG)
    aspace.connect()

    logging.basicConfig(level=logging.INFO)

    FILE = cliArguments.CSVname

    # Reads CSV file
    csv_file = pd.DataFrame(
        pd.read_csv(FILE, sep=",", header=0, index_col=False))

    # Creates new JSON file name
    JSON_FILE = FILE[:-4] + ".json"

    # Transforms CSV into JSON for parsing
logfileName = 'logs/aspace-import-%s.log' % datetime.datetime.now().isoformat()
#, filename=logfileName
logging.basicConfig(format='%(levelname)s|%(asctime)s|%(message)s',
                    level=logging.INFO)
logging.getLogger("requests").setLevel(
    logging.WARNING)  # Suppress oververbosity of requests logging
logging.getLogger("urllib3").setLevel(
    logging.WARNING)  # Same for urllib3 used by requests

# Set up jinja loader and template objects
templateLoader = jinja2.FileSystemLoader(searchpath=".")
templateEnv = jinja2.Environment(loader=templateLoader)

# Connect to ArchivesSpace
if DRY_RUN is not True:
    aspace = archivesspace.ArchivesSpace('http', 'localhost', '8089',
                                         'tchambers', 'sctchambers')
    aspace.connect()
else:
    logging.error('DRY RUN')


def asImportRecord(row, apiPath='', mapping=''):
    """This is the callback function to be run by the sheet processor on each row."""
    # load the jinja template
    template = templateEnv.get_template(mapping)
    # run the templater, merging the data into the template
    merged_data_yaml = template.render(row['data'])
    # convert the yaml format data into real python data
    asRecordDataStruct = load(merged_data_yaml, Loader=Loader)
    try:
        # The actual request to ASpace