def write_config(cfg):
    '''try writing config file to a default directory'''
    cfg_path = '/usr/local/etc/freelan'
    cfg_file = 'freelan_TEST.cfg'

    cfg_lines = []

    if not isinstance(cfg, FreelanCFG):
        if not isinstance(cfg, (list, tuple)):
            print("Freelan write input can not be processed.")
            return
        cfg_lines = cfg
    else:
        cfg_lines = cfg.build()

    if not os.path.isdir(cfg_path):
        print("Can not find default freelan config directory.")
        return

    cfg_file_path = os.path.join(cfg_path,cfg_file)

    if os.path.isfile( cfg_file_path ):
        print("freelan config file already exists - moving to not replace content.")
        ts = time.time()
        backup_file = cfg_file_path+'.ORG-'+datetime.datetime.fromtimestamp(ts).strftime('%y-%m-%d-%H-%M-%S')
        shutil.move(cfg_file_path, backup_file)

    cfg_lines = [cfg_line+'\n' for cfg_line in cfg_lines]

    with open(cfg_file_path, 'w') as cfg_f:
        cfg_f.writelines(cfg_lines)
def write_config ( cfg ) : cfg_path = '/usr/local/etc/freelan' cfg_file = 'freelan_TEST.cfg' cfg_lines = [ ] if not isinstance ( cfg , FreelanCFG ) : if not isinstance ( cfg , ( list , tuple ) ) : print ( "Freelan write input can not be processed." ) return cfg_lines = cfg else : cfg_lines = cfg . build ( ) if not os . path . isdir ( cfg_path ) : print ( "Can not find default freelan config directory." ) return cfg_file_path = os . path . join ( cfg_path , cfg_file ) if os . path . isfile ( cfg_file_path ) : print ( "freelan config file already exists - moving to not replace content." ) ts = time . time ( ) backup_file = cfg_file_path + '.ORG-' + datetime . datetime . fromtimestamp ( ts ) . strftime ( '%y-%m-%d-%H-%M-%S' ) shutil . move ( cfg_file_path , backup_file ) cfg_lines = [ cfg_line + '\n' for cfg_line in cfg_lines ] with open ( cfg_file_path , 'w' ) as cfg_f : cfg_f . writelines ( cfg_lines )
try writing config file to a default directory