Skip to content

Commit 6bd009d

Browse files
committed
Add ACTIONFILE_SEPARATOR environment variable
Before this commit, Windows paths (e.g. "C:\dir") were mishandled, because timestat split it into two action files ("C" and "\dir"). After this commit, the user can user the ACTIONFILE_SEPARATOR environment variable to choose a separator different from ':'. E.g., they can choose the ';' character for separator, which is customary on Windows (e.g., for the PATH environment variable).
1 parent 6b1ba8e commit 6bd009d

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

README.markdown

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Let's have a look at a quick demo of Timestat:
1919

2020
$ export ACTIONFILES=$HOME/myactionfile
2121

22+
# If you use Windows paths such as "C:\dir", you should replace the default
23+
# ":" separator with ";".
24+
#$ export ACTIONFILE_SEPARATOR=';'
25+
2226
$ timestat add mywork # Started to work on 'mywork'
2327

2428
$ timestat add myotherwork # 20 minutes later, started to work on

timestat

+48-2
Original file line numberDiff line numberDiff line change
@@ -1175,10 +1175,16 @@ Commands:
11751175
options.re_flags = re_flags
11761176

11771177
# Prepare: actionfiles
1178+
if os.getenv('ACTIONFILE_SEPARATOR') in (None, ''):
1179+
actionfile_separator = ':'
1180+
else:
1181+
actionfile_separator = os.getenv('ACTIONFILE_SEPARATOR')
1182+
11781183
if options.actionfiles is not None:
1179-
options.actionfiles = options.actionfiles.split(':')
1184+
options.actionfiles = options.actionfiles.split(actionfile_separator)
11801185
elif os.getenv('ACTIONFILES') not in (None, ''):
1181-
options.actionfiles = os.getenv('ACTIONFILES').split(':')
1186+
options.actionfiles = \
1187+
os.getenv('ACTIONFILES').split(actionfile_separator)
11821188
else:
11831189
# If there is no action file, don't proceed.
11841190
return options, args
@@ -1361,6 +1367,7 @@ class TestTimestat(unittest.TestCase):
13611367
# Empty environment variables
13621368
os.environ['EDITOR'] = ''
13631369
os.environ['ACTIONFILES'] = 'mock_actionfile_name'
1370+
os.environ['ACTIONFILE_SEPARATOR'] = ''
13641371

13651372
# Mock stdout
13661373
self.output = ''
@@ -2908,6 +2915,45 @@ class TestTimestat(unittest.TestCase):
29082915
'environment variable or give --actionfiles '
29092916
'argument!')
29102917

2918+
def test_multiple_action_files(self):
2919+
2920+
## 1. Colon works fine on linux as a separator between action files.
2921+
2922+
# 1/a. Use -f to pass the action file list.
2923+
os.environ['ACTIONFILES'] = ''
2924+
options, args = parse_args(['-f', 'first:second'])
2925+
self.assertEqual(options.actionfiles, ['first', 'second'])
2926+
2927+
# 1/b. Use environment variable to pass the action file list.
2928+
os.environ['ACTIONFILES'] = 'first:second'
2929+
options, args = parse_args([])
2930+
self.assertEqual(options.actionfiles, ['first', 'second'])
2931+
2932+
## 2. Windows paths misbehave when the drive is specified.
2933+
2934+
# 2/a. Use -f to pass the action file list.
2935+
os.environ['ACTIONFILES'] = ''
2936+
options, args = parse_args(['-f', 'C:\\dir1;D:\\dir2'])
2937+
self.assertEqual(options.actionfiles, ['C', '\\dir1;D', '\\dir2'])
2938+
2939+
# 2/b. Use environment variable to pass the action file list.
2940+
os.environ['ACTIONFILES'] = 'C:\\dir1;D:\\dir2'
2941+
options, args = parse_args([])
2942+
self.assertEqual(options.actionfiles, ['C', '\\dir1;D', '\\dir2'])
2943+
2944+
## 3. So we need to use ACTIONFILE_SEPARATOR in this situation.
2945+
os.environ['ACTIONFILE_SEPARATOR'] = ';'
2946+
2947+
# 3/a. Use -f to pass the action file list.
2948+
os.environ['ACTIONFILES'] = ''
2949+
options, args = parse_args(['-f', 'C:\\dir1;D:\\dir2'])
2950+
self.assertEqual(options.actionfiles, ['C:\\dir1', 'D:\\dir2'])
2951+
2952+
# 3/b. Use environment variable to pass the action file list.
2953+
os.environ['ACTIONFILES'] = 'C:\\dir1;D:\\dir2'
2954+
options, args = parse_args([])
2955+
self.assertEqual(options.actionfiles, ['C:\\dir1', 'D:\\dir2'])
2956+
29112957
def test_check_args(self):
29122958

29132959
def ok(a, b, arg_count):

0 commit comments

Comments
 (0)