forked from maxgarvey/research_group_ownership
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_file.py
47 lines (36 loc) · 1.58 KB
/
to_file.py
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
'''/to_file.py'''
from ownership import create_map
import os
def make_file(filename):
'''this method takes the name of the output file, determines if
it the script should be reevaluated or not. and then does so,
outputting to file.'''
#check to see if we have to run the lookup again, or if our current
#file is more recent than the most recent change
if os.path.isfile(filename):
our_timestamp = os.stat(filename).st_mtime #time stamp of csv file
www_timestamp = os.stat('/vol/www').st_mtime #time stamp of www
share_timestamp = os.stat('/vol/share').st_mtime #time stamp of share
#is our timestamp newer than the others?
if (our_timestamp > www_timestamp) and (our_timestamp > share_timestamp):
pass
#if not, make a new one!
else:
os.remove(filename)
make_file(filename)
#if the file doesn't already exist (or has just been erased), then
#we will create a new one.
else:
fd = open(filename, 'w') #works with py 2.4
share_map = create_map('/vol/share') #don't have sufficient privs for this
www_map = create_map('/vol/www') #do have sufficient privs for this
www_keys = www_map.keys()
share_keys = share_map.keys()
master_map = {}
for key in www_keys:
master_map[key] = www_map[key]
for key in share_keys:
master_map[key] = share_map[key]
for f in master_map.keys():
fd.write(f + ' , ' + master_map[f] + '\n')
fd.close() #works with py 2.4