#!/bin/env python
# -*- encoding: utf-8 -*-

##
#   @file SettingRTCConf.py
#   @brief 



import thread


import optparse
import sys,os,platform
import re
import time
import random
import commands
import math
import imp



import rtctree.tree







def getRTC(path):
    filename = path[-1].split(".")[0] + ".conf"
    f = open(filename, "w")
        
    
    tree = rtctree.tree.RTCTree(servers=path[1])
    d = ["/"]
    for p in path:
        if p != "":
            d.append(p)

    
    c = tree.get_node(d)

    print "Category: ", c.category

    s = "configuration.active_config: "
    s += str(c.active_conf_set_name)
    s += "\n"

    f.write(s)

    confList = c.conf_sets
    for k, v in confList.items():
        #print k
        for i,j in v.data.items():
            s = "conf."
            s += str(k)
            s += "."
            s += str(i)
            s += ": "
            s += str(j)
            s += "\n"
            f.write(s)

    
    ec = c.owned_ecs[0]
    s = "exec_cxt.periodic.rate: "
    s += str(ec.rate)
    s += "\n"

    f.write(s)
    

    f.close()
    
    

    


        

def main():
    
    path = sys.argv[1]
    path = path.split("/")

    getRTC(path)
    
    
    
    
    

    
    
    
if __name__ == "__main__":
    main()
