diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-15 18:01:03 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-15 18:01:03 -0700 |
commit | 508168acb95aee070d493b45656f781a42bdd262 (patch) | |
tree | e816b241c500d99f1289fb6afffb33abb560df99 /cloudinit/transforms/cc_locale.py | |
parent | 36c1da35c2c0cb1b2ee18b7374bc81df8349e3e2 (diff) | |
download | vyos-cloud-init-508168acb95aee070d493b45656f781a42bdd262.tar.gz vyos-cloud-init-508168acb95aee070d493b45656f781a42bdd262.zip |
Complete initial cleanup for refactoring/rework.
Some of the cleanups were the following
1. Using standard (logged) utility functions for sub process work, writing, reading files, and other file system/operating system options
2. Having distrobutions impelement there own subclasses to handle system specifics (if applicable)
3. Having a cloud wrapper that provides just the functionality we want to expose (cloud.py)
4. Using a path class instead of globals for all cloud init paths (it is configured via config)
5. Removal of as much shared global state as possible (there should be none, minus a set of constants)
6. Other various cleanups that remove transforms/handlers/modules from reading/writing/chmoding there own files.
a. They should be using util functions to take advantage of the logging that is now enabled in those util functions (very useful for debugging)
7. Urls being read and checked from a single module that serves this and only this purpose (+1 for code organization)
8. Updates to log whenever a transform decides not to run
9. Ensure whenever a exception is thrown (and possibly captured) that the util.logexc function is called
a. For debugging, tracing this is important to not just drop them on the floor.
10. Code shuffling into utils.py where it makes sense (and where it could serve a benefit for other code now or in the future)
Diffstat (limited to 'cloudinit/transforms/cc_locale.py')
-rw-r--r-- | cloudinit/transforms/cc_locale.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/cloudinit/transforms/cc_locale.py b/cloudinit/transforms/cc_locale.py index 2bb22fdb..3fb4c5d9 100644 --- a/cloudinit/transforms/cc_locale.py +++ b/cloudinit/transforms/cc_locale.py @@ -18,22 +18,28 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import cloudinit.util as util -import os.path -import subprocess -import traceback +import os +from cloudinit import templater +from cloudinit import util -def apply_locale(locale, cfgfile): + +def apply_locale(locale, cfgfile, cloud, log): + # TODO this command might not work on RH... if os.path.exists('/usr/sbin/locale-gen'): - subprocess.Popen(['locale-gen', locale]).communicate() + util.subp(['locale-gen', locale], capture=False) if os.path.exists('/usr/sbin/update-locale'): - subprocess.Popen(['update-locale', locale]).communicate() - - util.render_to_file('default-locale', cfgfile, {'locale': locale}) + util.subp(['update-locale', locale], capture=False) + if not cfgfile: + return + template_fn = cloud.get_template_filename('default-locale') + if not template_fn: + log.warn("No template filename found to write to %s", cfgfile) + else: + templater.render_to_file(template_fn, cfgfile, {'locale': locale}) -def handle(_name, cfg, cloud, log, args): +def handle(name, cfg, cloud, log, args): if len(args) != 0: locale = args[0] else: @@ -43,12 +49,10 @@ def handle(_name, cfg, cloud, log, args): "/etc/default/locale") if not locale: + log.debug(("Skipping module named %s, " + "no 'locale' configuration found"), name) return - log.debug("setting locale to %s" % locale) + log.debug("Setting locale to %s", locale) - try: - apply_locale(locale, locale_cfgfile) - except Exception as e: - log.debug(traceback.format_exc(e)) - raise Exception("failed to apply locale %s" % locale) + apply_locale(locale, locale_cfgfile, cloud, log) |