aboutsummaryrefslogtreecommitdiff
path: root/qolab/file_utils
diff options
context:
space:
mode:
Diffstat (limited to 'qolab/file_utils')
-rw-r--r--qolab/file_utils/__init__.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/qolab/file_utils/__init__.py b/qolab/file_utils/__init__.py
index 9b7aeb2..d612c19 100644
--- a/qolab/file_utils/__init__.py
+++ b/qolab/file_utils/__init__.py
@@ -4,9 +4,13 @@ import os
from datetime import date
def filename2os_fname( fname ):
- # filename2os_fname translate Win or Linux fname to OS dependent style
- # takes in account the notion of 'Z:' drive on different systems
- # Z:\dir1\dir2\file <==> /mnt/qol_grp_data/dir1/dir2/file
+ r"""Translate Windows or Linux filename to OS dependent style.
+ Takes in account the notion of 'Z:' drive on different systems.
+
+ In particular replaces Z: <==> /mnt/qol_grp_data and \\ <==> /
+
+ Example: Z:\\dir1\\dir2\\file <==> /mnt/qol_grp_data/dir1/dir2/file
+ """
if platform.system() == 'Windows':
fname = re.sub('/mnt/qol_grp_data', 'Z:', fname)
else:
@@ -18,12 +22,12 @@ def filename2os_fname( fname ):
def get_runnum(data_dir):
- # For the provided data_dir:
- # reads, increments data counter and saves it back.
- # If necessary creates counter file and full path to it.
- # example
- # get_runnum('Z:\Ramsi_EIT\data\')
- # get_runnum('/mnt/qol_grp_data/data')
+ r""" Reads, increments data counter and saves it back in the provided `data_dir`.
+ If necessary creates counter file and full path to it.
+ Examples":
+ get_runnum('Z:\\Ramsi_EIT\\data\\')
+ get_runnum('/mnt/qol_grp_data/data')
+ """
data_dir = filename2os_fname( data_dir );
if not os.path.exists(data_dir):
os.mkdir(data_dir)
@@ -61,6 +65,10 @@ def get_runnum(data_dir):
return(run_number)
def get_next_data_file(prefix, savepath, run_number=None, datestr=None, date_format='%Y%m%d', extension='dat'):
+ """Generate a filename according to a standard naming scheme
+ fname = os.path.join(savepath, f'{prefix}_{datestr}_{run_number:05d}.{extension}')
+ if run_number is missing, acquires it with `get_runnum( savepath )`
+ """
if run_number is None:
run_number = get_runnum( savepath )
today = date.today()