changes for 3.0
[monitor.git] / automate.py
1 import csv
2 from glob import glob
3 import os
4 import time
5
6 def time_to_str(t):
7         return time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(t))
8
9 def get_filelist_from_dir(dirname):
10         filelist = glob("%s/*.out" % dirname)
11
12         ret_list = []
13         for file in filelist:
14                 ret_list.append(file)
15         return ret_list
16
17 def get_hostlist_from_dir(dirname):
18         filelist = glob("%s/*.out" % dirname)
19
20         ret_list = []
21         for file in filelist:
22                 ret_list.append([os.path.basename(file)[:-4], ''])
23         return ret_list
24
25 def csv_to_hash(r):
26         ret = {}
27         for line in r:
28                 (k,v) = (line[0], line[1])
29                 if k not in ret:
30                         ret[k] = v
31                 else:
32                         # multiple values for the same key
33                         if isinstance(ret[k], list):
34                                 ret[k].append(v)
35                         else:
36                                 ret[k] = [ret[k], v]
37         return ret
38
39 def getcsv(file):
40         return csv_to_hash(csv.reader(open(file,'r')))