adios_db.scripting package

Assorted utilities to help with writing scripts that use the oil database

adios_db.scripting.find_highest_id(prefix, oil_path)

find the highest id of the records with a given prefix.

Parameters:
  • prefix – two-char prefix of the IDs

  • oil_path – Path where the oil JSON files are.

NOTE: this assumes that the file names match the ID

adios_db.scripting.get_all_records(data_dir)

gets all the records from the JSON data stored in gitLab

This is a generator that gets all the records, returning them one by one as record, path pairs

Parameters:

data_dir – the directory that holds the data

The record returned is an Oil object

Use as such::
for oil, path in get_all_records(data_dir):

work_with_the_record

adios_db.scripting.process_input(USAGE='\ndo_something.py:  data_dir [dry_run]\n\ndata_dir is a where the data are: the script will recursively\nsearch for JSON files\n\nIf "dry_run" is on the command line, it will report what it would do,\nbut not save any changes\n')

process sys.argv to get the path and whether it’s a dry_run or not

Parameters:

USAGE=USAGE – the usage message to return print if there’s an error in the input – default provided

Returns base_dir, dry_run:

base_dir is a Path object of the dir passed in. dry_run is True if “dry_run” is on the command line.