i have tool, intended generate , display configurations (sections).
ini-file looks like:
... [test] math_dll = 035f210e-6c06-4021-8857-0759409c4bb7 math_dll_xml = 805fe0f0-2627-4ced-bac5-8725ef9839ef assetmanager_api_dll = 426d1824-628f-47ed-8539-4a0ed292b94e ... what want - add option remove section "main" file:
... parser_unity.add_argument('-x', '--remove', action='store', dest='unity_uuid_remove', help='remove configuration uuids.ini. must called config_name delete') ... and:
def handler_unity(action_list): ... if action_list.unity_uuid_remove: lib.unity.uuidgen import uuuidmanagment u = uuuidmanagment(logger, rds_basedir) u.config_remove(action_list.unity_uuid_remove) and class , method:
class uuuidmanagment(object): """class data in uuids.ini file management""" def __init__(self, logger, rds_basedir): self.config = configparser.configparser() self.config_file = os.path.join(rds_basedir, 'conf', 'unity', 'uuids.ini') self.config.read(self.config_file) self.configs = self.config.sections() self.logger = logger self.rds_basedir = rds_basedir ... def config_remove(self, config_name): """remove config_name specified in argument uuids.ini""" self.logger.logger.info('remove %s' % config_name) print(self.config, self.configs, config_name) self.config.remove_section(config_name) open(self.config_file, 'r+') out: self.config.write(out) but it's don't want work.
current configs:
d:\rds\rdsmanager>rdsmanager.py unity -l rdsmanager started @ 09, jul 2015 @ 17:05:35 running configlist avalable configurations: develop debug qa version_1_0_2_staging test remove it:
d:\rds\rdsmanager>rdsmanager.py unity -x test rdsmanager started @ 09, jul 2015 @ 17:05:40 remove test (<lib.external.configparser.configparser instance @ 0x02346580>, ['develop', 'debug', 'qa', 'version_1_0_2_staging', 'test'], 'test') check again:
d:\rds\rdsmanager>rdsmanager.py unity -l rdsmanager started @ 09, jul 2015 @ 17:05:42 running configlist avalable configurations: develop debug qa version_1_0_2_staging test
in config_remove open file in r+ mode.
you should open in write/truncate mode w rewrite file, can see in doc.
'w' writing (truncating file if exists)
for more information, question: confused python file mode “w+” related actual purpose of + variants.
Comments
Post a Comment