diff options
author | Sol Jerome <sol.jerome@gmail.com> | 2012-10-26 15:05:51 -0500 |
---|---|---|
committer | Sol Jerome <sol.jerome@gmail.com> | 2012-10-26 15:05:51 -0500 |
commit | 59b3d315c402e72120d2d12a0f08f58bdff98aeb (patch) | |
tree | 65eef580764261e9b622ca7452664809e234df7c | |
parent | bcb99a6e2fb3a07591f40275e7b6e7d6ad42caa5 (diff) | |
download | bcfg2-59b3d315c402e72120d2d12a0f08f58bdff98aeb.tar.gz bcfg2-59b3d315c402e72120d2d12a0f08f58bdff98aeb.tar.bz2 bcfg2-59b3d315c402e72120d2d12a0f08f58bdff98aeb.zip |
tools: Add migrate_perms_to_mode tool
Helps users to migrate their repositories from the perms attribute to
mode.
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
-rw-r--r-- | tools/upgrade/1.3/README | 4 | ||||
-rw-r--r-- | tools/upgrade/1.3/migrate_perms_to_mode.py | 68 |
2 files changed, 72 insertions, 0 deletions
diff --git a/tools/upgrade/1.3/README b/tools/upgrade/1.3/README index e72650729..2831d8f00 100644 --- a/tools/upgrade/1.3/README +++ b/tools/upgrade/1.3/README @@ -15,3 +15,7 @@ service_modes.py migrate_dbstats.py - Convert old DBStats entries to the new Reporting system + +migrate_perms_to_mode.py + - Convert perms attribute to mode (note that if you have info/:info + files, you should run migrate_info.py first) diff --git a/tools/upgrade/1.3/migrate_perms_to_mode.py b/tools/upgrade/1.3/migrate_perms_to_mode.py new file mode 100644 index 000000000..0aa9c574c --- /dev/null +++ b/tools/upgrade/1.3/migrate_perms_to_mode.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +import lxml.etree +import os +import sys + +import Bcfg2.Options + + +def setmodeattr(elem): + """Set the mode attribute for a given element.""" + if elem.attrib.has_key('perms'): + elem.set('mode', elem.get('perms')) + del elem.attrib['perms'] + return True + + +def writefile(f, xdata): + """Write xml data to a file""" + newfile = open(f, 'w') + newfile.write(lxml.etree.tostring(xdata, pretty_print=True)) + newfile.close() + + +def convertinfo(ifile): + """Do perms -> mode conversion for info.xml files.""" + xdata = lxml.etree.parse(ifile) + found = False + for i in xdata.findall('//Info'): + found = setmodeattr(i) + if found: + writefile(ifile, xdata) + + +def convertstructure(structfile): + """Do perms -> mode conversion for structure files.""" + xdata = lxml.etree.parse(structfile) + found = False + for path in xdata.findall('//BoundPath'): + found = setmodeattr(path) + for path in xdata.findall('//Path'): + found = setmodeattr(path) + if found: + writefile(structfile, xdata) + + +def main(): + opts = dict(repo=Bcfg2.Options.SERVER_REPOSITORY, + configfile=Bcfg2.Options.CFILE, + plugins=Bcfg2.Options.SERVER_PLUGINS) + setup = Bcfg2.Options.OptionParser(opts) + setup.parse(sys.argv[1:]) + repo = setup['repo'] + + for plugin in setup['plugins']: + if plugin in ['Base', 'Bundler', 'Rules']: + for root, dirs, files in os.walk(os.path.join(repo, plugin)): + for fname in files: + convertstructure(os.path.join(root, fname)) + if plugin not in ['Cfg', 'TGenshi', 'TCheetah']: + continue + for root, dirs, files in os.walk(os.path.join(repo, plugin)): + for fname in files: + if fname == 'info.xml': + convertinfo(os.path.join(root, fname)) + +if __name__ == '__main__': + sys.exit(main()) |