dbprocessing.Utils¶
Various utilities of use throughout this code.
Functions
|
Return a long iterable in a tuple of shorter lists. |
|
Return a string of the date format for printing on the screen |
|
Given a daterange return the date objects for all days in the range |
|
Given an input datetime.datetime or datetime.date return a datetime.date |
|
Do any substitutions that are needed to put thing in the right place |
|
Given a start and a stop date make all the dates in between |
|
Flatten an irregularly nested list of lists |
|
Given a date of the for yyyy-mm-dd parse to a datetime. |
|
Given a format of the form x.y.z parse to a Version |
|
Given a PID see if it is currently running. |
|
Print a progress bar with urllib.urlretrieve reporthook functionality |
|
Read a database definition config file. |
|
Split a string with a bunch of command line arguments into a list |
|
Read in the arguments string from the db and change to a dict |
|
Returns true if passed 'True', 'true', True, 1, 'Yes', 'yes', 'Y', or 'y' |
|
Convert a date, date string, or datetime to a datetime |
|
Returns None if passed '', 'None', 'none', or 'NONE' |
|
Take a list and return only the unique elements in the same order |
- dbprocessing.Utils.dateForPrinting(dt=None, microseconds=False, brackets='[]')[source]¶
Return a string of the date format for printing on the screen
If dt is
None
returnnow()
.- Parameters
- Returns
- str
Iso formatted string
Examples
>>> from dbprocessing.Utils import dateForPrinting >>> print("{0} Something occurred".format(dateForPrinting())) [2016-03-22T10:51:45] Something occurred
- dbprocessing.Utils.daterange_to_dates(daterange)[source]¶
Given a daterange return the date objects for all days in the range
- dbprocessing.Utils.datetimeToDate(dt)[source]¶
Given an input datetime.datetime or datetime.date return a datetime.date
- dbprocessing.Utils.dirSubs(path, filename, utc_file_date, utc_start_time, version, dbu=None)[source]¶
Do any substitutions that are needed to put thing in the right place
Todo
This may be useless/could be made more useful
Honored substitutions used as {Y}{PRODUCT}{DATE}
- Parameters
- Returns
Notes
- Valid subsitutions are:
Y: 4 digit year
m: 2 digit month
b: 3 character month (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)
d: 2 digit day
y: 2 digit year
j: 3 digit day of year
H: 2 digit hour (24-hour time)
M: 2 digit minute
S: 2 digit second
VERSION: version string, interface.quality.revision
DATE: the UTC date from a file, same as Ymd
MISSION: the mission name from the db
SPACECRAFT: the spacecraft name from the db
PRODUCT: the product name from the db
- dbprocessing.Utils.expandDates(start_time, stop_time)[source]¶
Given a start and a stop date make all the dates in between
Inclusive on the ends
- dbprocessing.Utils.flatten(l)[source]¶
Flatten an irregularly nested list of lists
Taken from https://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists
- dbprocessing.Utils.parseDate(inval)[source]¶
Given a date of the for yyyy-mm-dd parse to a datetime.
This is just a wrapper around
strptime()
If the format is wrong ValueError is raised.
- dbprocessing.Utils.parseVersion(inval)[source]¶
Given a format of the form x.y.z parse to a Version
This is a wrapper around
fromString()
.
- dbprocessing.Utils.processRunning(pid)[source]¶
Given a PID see if it is currently running.
Taken from from https://stackoverflow.com/questions/568271/how-to-check-if-there-exists-a-process-with-a-given-pid-in-python
- dbprocessing.Utils.progressbar(count, blocksize, totalsize, text='Download Progress')[source]¶
Print a progress bar with urllib.urlretrieve reporthook functionality
Taken from spacepy
- Parameters
Examples
>>> import spacepy.toolbox as tb >>> import urllib >>> urllib.urlretrieve(config['psddata_url'], PSDdata_fname, reporthook=tb.progressbar)
- dbprocessing.Utils.readconfig(config_filepath)[source]¶
Read a database definition config file.
- Parameters
- config_filepath
str
full path to the config file
- config_filepath
- Returns
dict
Dictionary of key value pairs from config files
See also
- dbprocessing.Utils.split_code_args(args)[source]¶
Split a string with a bunch of command line arguments into a list
As needed by Popen
This is different than just split() since we have to keep options together with the flags.
- Parameters
- args
str
- args
- Returns
- :class:`list` ofclass:str
See also
Examples
>>> split_code_args("code -n hello outfile") [code, -n hello, outfile]
- dbprocessing.Utils.strargs_to_args(strargs)[source]¶
Read in the arguments string from the db and change to a dict
- dbprocessing.Utils.toBool(value)[source]¶
Returns true if passed ‘True’, ‘true’, True, 1, ‘Yes’, ‘yes’, ‘Y’, or ‘y’
- Parameters
- value
Value to evaluate if true
- Returns
- dbprocessing.Utils.toDatetime(dt, end=False)[source]¶
Convert a date, date string, or datetime to a datetime
If a time is provided, passed through; otherwise set to start/end of day.
- dbprocessing.Utils.toNone(value)[source]¶
Returns None if passed ‘’, ‘None’, ‘none’, or ‘NONE’
- Parameters
- value
Value to evaluate if none
- Returns
- any
None
or same input value
- dbprocessing.Utils.unique(seq)[source]¶
Take a list and return only the unique elements in the same order
Release: 0.1.0 Doc generation date: Feb 10, 2022