X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=automate%2Fautomate.py;fp=automate%2Fautomate.py;h=2c67ffe97936aa3d10b1b5fdc6aa2e9f041b64d5;hb=0fabfc8dbe8f1f2c0d12397e1bc8c6ed686fb5ed;hp=0000000000000000000000000000000000000000;hpb=d0e06b11cf33ded60e15f9c1ab81eeeba05d3c0a;p=monitor.git diff --git a/automate/automate.py b/automate/automate.py new file mode 100644 index 0000000..2c67ffe --- /dev/null +++ b/automate/automate.py @@ -0,0 +1,40 @@ +import csv +from glob import glob +import os +import time + +def time_to_str(t): + return time.strftime("%Y/%m/%d %H:%M:%S", time.gmtime(t)) + +def get_filelist_from_dir(dirname): + filelist = glob("%s/*.out" % dirname) + + ret_list = [] + for file in filelist: + ret_list.append(file) + return ret_list + +def get_hostlist_from_dir(dirname): + filelist = glob("%s/*.out" % dirname) + + ret_list = [] + for file in filelist: + ret_list.append([os.path.basename(file)[:-4], '']) + return ret_list + +def csv_to_hash(r): + ret = {} + for line in r: + (k,v) = (line[0], line[1]) + if k not in ret: + ret[k] = v + else: + # multiple values for the same key + if isinstance(ret[k], list): + ret[k].append(v) + else: + ret[k] = [ret[k], v] + return ret + +def getcsv(file): + return csv_to_hash(csv.reader(open(file,'r')))