forked from dannyjacobs/obs_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily_move_pot0.py
More file actions
executable file
·51 lines (42 loc) · 1.4 KB
/
Copy pathdaily_move_pot0.py
File metadata and controls
executable file
·51 lines (42 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""
Move all data in the specified directory into daily subdirectories. Day defined as the round JD. This is fine for SA GMT+2 and GB GMT-4
Assumes filenames of the type
<prefix>.2455900.154677.<postfix>
The files:
zen.2455899.1234.uv
zen.2455900.5745.uv
Will go to
psa899/zen.2455899.1234.uv
psa900/zen.2455900.5745.uv
usage:
daily_move.py /path/to/data/z*uv
"""
DEBUG = False
import sys,glob as gl,os,shutil
#make relevant paths
rootdir = sys.argv[-1]
if rootdir[-1]==os.path.sep: rootdir = rootdir[:-1]
rootdir = os.path.dirname(rootdir)
prefix = 'psa'
dir_prefix = os.path.join(rootdir,prefix)
#find files
allfiles = sys.argv[1:]
JDs = [name.split('.')[1] for name in allfiles]
tJDs = [name.split('.')[1][-4:] for name in allfiles] #tJD = truncated Julian Date
paths = dict(zip(allfiles,[dir_prefix+tJD for tJD in tJDs]))
unique_tJDs = set(tJDs)
mkdirs = dict(zip(unique_tJDs,[dir_prefix+unique_tJD+'/' for unique_tJD in unique_tJDs]))
if DEBUG: print "creating directories"
#make the target directories
for tJD in unique_tJDs:
print mkdirs[tJD],'..',
if not os.path.exists(mkdirs[tJD]):
os.mkdir(mkdirs[tJD])
if DEBUG: print "[created]"
else:
if DEBUG:print '[exists]'
if DEBUG: "I would have moved the following %d files"%(len(allfiles))
for FILE in paths:
print os.path.join(paths[FILE],os.path.basename(FILE))
if not DEBUG: shutil.move(FILE,paths[FILE])