コード例 #1
0
def create_config(LastUpdateDate):
    print(f'{bcolors.HEADER}Start create_config')
    config = configparser.ConfigParser()
    config.add_section("Settings")
    config.set("Settings", "LastUpdateDate", str(LastUpdateDate))
    with open(_file_locald_ini, "w") as config_file:
        config.write(config_file)
    print(f'{bcolors.OKGREEN}create_config = {_file_locald_ini},{config_file}')
コード例 #2
0
def saveResult(result):
    config = ConfigParser.ConfigParser()
    config.add_section('Result')
    config.set('Result', 'moments', "\n"+"\n".join(map(lambda arg: " ".join(map(str, arg)), result['moments'])))
    config.set('Result', 'density', "\n"+"\n".join(map(lambda arg: " ".join(map(str, arg)), result['density'])))
    config.set('Result', 'bprob',   " ".join(map(str, result['bprob'])))
    config.set('Result', 'mpost',   " ".join(map(str, result['mpost'])))
    configfile = open(options['save'], 'wb')
    config.write(configfile)
コード例 #3
0
ファイル: deploy.py プロジェクト: pritishmishra/xmake
def _storeStageCloseProps(nexusApi, build_cfg, repoId, snapshot_url):

    status = nexusApi.getrepositorystatus(repoId)

    config = ConfigParser.ConfigParser()
    config.add_section('stageclose')
    config.set('stageclose', 'staging.repo.url', status['repositoryURI'])
    config.set('stageclose', 'staging.repo.id', repoId)
    config.set('stageclose', 'git.repo', snapshot_url.split('@')[0])
    config.set('stageclose', 'git.treeish', snapshot_url.split('@')[1])
    with open(build_cfg.close_stage_props_file(), 'w') as f:
        config.write(f)
コード例 #4
0
def saveResult(result):
    config = ConfigParser.ConfigParser()
    config.add_section('Sampling Result')
    config.set('Sampling Result', 'counts',    "\n"+"\n".join(map(lambda arg: " ".join(map(str, arg)), result['counts'])))
    config.set('Sampling Result', 'moments',   "\n"+"\n".join(map(lambda arg: " ".join(map(str, arg)), result['moments'])))
    config.set('Sampling Result', 'density',   "\n"+"\n".join(map(lambda arg: " ".join(map(str, arg)), result['density'])))
    config.set('Sampling Result', 'samples',   " ".join(map(str, result['samples'])))
    config.set('Sampling Result', 'utility',   " ".join(map(str, result['utility'])))
    config.set('Sampling Result', 'bprob',     " ".join(map(str, result['bprob'])))
    config.set('Sampling Result', 'mpost',     " ".join(map(str, result['mpost'])))
    config.set('Sampling Result', 'distances', " ".join(map(str, result['distances'])))
    config.set('Sampling Result', 'states',    "\n".join(map(str, result['states'])))
    configfile = open(options['save'], 'wb')
    config.write(configfile)
    configfile.close()
コード例 #5
0
ファイル: swinelib.py プロジェクト: dswd/Swine
 def migrateOldConfig(self): #Legacy support code
   import ConfigParser, ast
   config = ConfigParser.ConfigParser()
   if os.path.exists(self.getOldConfigFile()):
     with codecs.open(self.getOldConfigFile(), "r", "utf8") as fp:
       config.readfp(fp)
   if not config.has_section("__SYSTEM__"):
     config.add_section("__SYSTEM__")
   self.settings = dict(config.items("__SYSTEM__"))
   for name in config.sections():
     if name != "__SYSTEM__":
       dat = dict(config.items(name))
       if dat["program"] and dat["program"].startswith("["):
         args = ast.literal_eval(dat["program"])
       else:
         args = shlex.split(str(dat["program"]))
       dat["program"] = args[0]
       if "\\\\" in dat["program"]:
         dat["program"] = ast.literal_eval('"'+dat["program"]+'"')
       dat["arguments"] = args[1:]
       self.shortcutData[name] = dat
コード例 #6
0
ファイル: setup.py プロジェクト: TomAlanCarroll/synthia
def add_username_to_config_ini(username):
    config = SafeConfigParser()
    config.read('config.ini')

    if not config.has_section('main'):
        config.add_section('main')
        config.set('main', 'users', username)
    else:
        users = config.get('main', 'users')

        user_already_in_config = False
        for user in users.split(','):
            if user == username:
                user_already_in_config = True
                break

        if user_already_in_config is False:
            config.set('main', 'users', users + ',' + username)

    with open('config.ini', 'w') as f:
        config.write(f)
コード例 #7
0
ファイル: message.py プロジェクト: JeremyGrosser/ietfnotify
def checkRequired(parsed):
	log.log(log.DEBUG, 'Checking required fields')
	if not 'doc-tag' in parsed:
		log.log(log.ERROR, 'No tag specified')
		return (1, 'No tag specified')
	tag = parsed['doc-tag'][0].split('-', 1)
	event_type = tag[0]

	if config.has_section('fields-' + event_type):
		items = config.items('fields-' + event_type)
		for i in items:
			if i[0] == 'required':
				required_fields = i[1].split(', ')
				for field in required_fields:
					if not field in parsed:
						log.log(log.ERROR, 'Required field "' + field + '" is missing')
						return (1, 'Required field "' + field + '" is missing')
			elif i[0] == 'optional':
				return (0, '')
				#optional_fields = i[1].split(', ')
				#for field in optional_fields:
				#	if field in parsed:
				#		pass
			else:
				log.log(log.ERROR, 'Unknown definition in config: ' + repr(i))
				return (1, 'Unknown definition in config: ' + repr(i))
	else:
		log.log(log.ERROR, 'Event type not specified in config file. Adding section. All fields will be added as optional. Fix this soon.')
		config.add_section('fields-' + event_type)
		oldkey = ''
		for key in parsed:
			if oldkey == '':
				newkey = key
			else:
				newkey = oldkey + ', ' + key
			config.set('fields-' + event_type, 'optional', newkey)
			oldkey = config.get('fields-' + event_type, 'optional')
		config.write()
		return (0, '')
コード例 #8
0
ファイル: admin.py プロジェクト: armooo/pytivo
    def UpdateSettings(self, handler, query):
        config = ConfigParser.ConfigParser()
        config.read(config_file_path)
        for key in query:
            if key.startswith('Server.'):
                section, option = key.split('.')
                if option == "new__setting":
                    new_setting = query[key][0]
                    continue
                if option == "new__value":
                    new_value = query[key][0]
                    continue
                if query[key][0] == " ":
                    config.remove_option(section, option)                      
                else:
                    config.set(section, option, query[key][0])
        if not(new_setting == ' ' and new_value == ' '):
            config.set('Server', new_setting, new_value)
           
        sections = query['Section_Map'][0].split(']')
        sections.pop() #last item is junk
        for section in sections:
            ID, name = section.split('|')
            if query[ID][0] == "Delete_Me":
                config.remove_section(name)
                continue
            if query[ID][0] != name:
                config.remove_section(name)
                config.add_section(query[ID][0])
            for key in query:
                if key.startswith(ID + '.'):
                    junk, option = key.split('.')
                    if option == "new__setting":
                        new_setting = query[key][0]
                        continue
                    if option == "new__value":
                        new_value = query[key][0]
                        continue
                    if query[key][0] == " ":
                        config.remove_option(query[ID][0], option)                      
                    else:
                        config.set(query[ID][0], option, query[key][0])
            if not(new_setting == ' ' and new_value == ' '):
                config.set(query[ID][0], new_setting, new_value)
        if query['new_Section'][0] != " ":
            config.add_section(query['new_Section'][0])
        f = open(config_file_path, "w")
        config.write(f)
        f.close()

        subcname = query['Container'][0]
        cname = subcname.split('/')[0]
        handler.send_response(200)
        handler.end_headers()
        t = Template(file=os.path.join(SCRIPTDIR,'templates', 'redirect.tmpl'))
        t.container = cname
        t.time = '10'
        t.url = '/TiVoConnect?Command=Admin&Container=' + cname
        t.text = '<h3>Your Settings have been saved.</h3>  <br>You settings have been saved to the pyTivo.conf file.'+\
                 'However you will need to do a <b>Soft Reset</b> before these changes will take effect.'+\
                 '<br> The <a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 10 seconds.'
        handler.wfile.write(t)
コード例 #9
0
    def UpdateSettings(self, handler, query):
        config = ConfigParser.ConfigParser()
        config.read(config_file_path)
        for key in query:
            if key.startswith('Server.'):
                section, option = key.split('.')
                if option == "new__setting":
                    new_setting = query[key][0]
                    continue
                if option == "new__value":
                    new_value = query[key][0]
                    continue
                if query[key][0] == " ":
                    config.remove_option(section, option)
                else:
                    config.set(section, option, query[key][0])
        if not (new_setting == ' ' and new_value == ' '):
            config.set('Server', new_setting, new_value)

        sections = query['Section_Map'][0].split(']')
        sections.pop()  #last item is junk
        for section in sections:
            ID, name = section.split('|')
            if query[ID][0] == "Delete_Me":
                config.remove_section(name)
                continue
            if query[ID][0] != name:
                config.remove_section(name)
                config.add_section(query[ID][0])
            for key in query:
                if key.startswith(ID + '.'):
                    junk, option = key.split('.')
                    if option == "new__setting":
                        new_setting = query[key][0]
                        continue
                    if option == "new__value":
                        new_value = query[key][0]
                        continue
                    if query[key][0] == " ":
                        config.remove_option(query[ID][0], option)
                    else:
                        config.set(query[ID][0], option, query[key][0])
            if not (new_setting == ' ' and new_value == ' '):
                config.set(query[ID][0], new_setting, new_value)
        if query['new_Section'][0] != " ":
            config.add_section(query['new_Section'][0])
        f = open(config_file_path, "w")
        config.write(f)
        f.close()

        subcname = query['Container'][0]
        cname = subcname.split('/')[0]
        handler.send_response(200)
        handler.end_headers()
        t = Template(
            file=os.path.join(SCRIPTDIR, 'templates', 'redirect.tmpl'))
        t.container = cname
        t.time = '10'
        t.url = '/TiVoConnect?Command=Admin&Container=' + cname
        t.text = '<h3>Your Settings have been saved.</h3>  <br>You settings have been saved to the pyTivo.conf file.'+\
                 'However you will need to do a <b>Soft Reset</b> before these changes will take effect.'+\
                 '<br> The <a href="/TiVoConnect?Command=Admin&Container='+ cname +'"> Admin</a> page will reload in 10 seconds.'
        handler.wfile.write(t)