datadir
This commit is contained in:
parent
59780af3a3
commit
be044a9768
|
@ -1,14 +1,33 @@
|
|||
import os
|
||||
import datetime as dt
|
||||
import calendar
|
||||
import os
|
||||
import re
|
||||
|
||||
DEFAULT_BASEPTH='dataDir'
|
||||
DEFAULT_BASEPTH = '~/cds_dataDir'
|
||||
|
||||
def cds_datadir(basepath=DEFAULT_BASEPTH):
|
||||
#strike_time = dt.datetime.strptime('01/01/79 00:00:00.000', '%m/%d/%y %H:%M:%S.%f')
|
||||
#DAY = (dt.datetime.now() - strike_time).total_seconds() # seconds from the first day of the observation
|
||||
tstamp = calendar.timegm(dt.datetime.now().timetuple())
|
||||
datadir = os.path.join( basepath,str(tstamp)) #
|
||||
os.makedirs(datadir)
|
||||
def cds_datadir(label=None, basepath=DEFAULT_BASEPTH, verbose=True):
|
||||
# Expand user directory
|
||||
basepath = os.path.expanduser(basepath)
|
||||
|
||||
# Get current timestamp in readable format
|
||||
timestamp = dt.datetime.now().strftime('%Y_%m_%d_%H_%M_%S')
|
||||
|
||||
# Sanitize and truncate label if provided
|
||||
if label:
|
||||
sanitized_label = re.sub(r'[^a-zA-Z0-9_-]', '', label)[:20]
|
||||
else:
|
||||
sanitized_label = ''
|
||||
|
||||
# Create directory name with optional label
|
||||
folder_name = f"out_{timestamp}_{sanitized_label}" if sanitized_label else f"out_{timestamp}"
|
||||
datadir = os.path.join(basepath, folder_name)
|
||||
|
||||
# Create the directory
|
||||
os.makedirs(datadir, exist_ok=True)
|
||||
if verbose:
|
||||
print ("datadir: %s", datadir )
|
||||
return datadir
|
||||
|
||||
# Example usage
|
||||
directory = cds_datadir(label='example_label')
|
||||
print(directory)
|
||||
|
|
Loading…
Reference in New Issue