From 51be118f8521d22df6b7bd63a2a28850359045ae Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Fri, 15 May 2015 09:16:15 +0200 Subject: [PATCH] Change dir to form config directory in main method, not in a class. --- src/scriptform.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/scriptform.py b/src/scriptform.py index 30a2c05..3e32750 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -187,7 +187,6 @@ class ScriptForm: def __init__(self, config_file, cache=True): self.config_file = config_file self.cache = cache - self.basepath = os.path.realpath(os.path.dirname(config_file)) self.log = logging.getLogger('SCRIPTFORM') self.get_form_config() # Init form config so it can raise errors about problems. self.websrv = None @@ -201,8 +200,7 @@ class ScriptForm: if self.cache and hasattr(self, 'form_config_singleton'): return self.form_config_singleton - path = self.config_file - config = json.load(file(path, 'r')) + config = json.load(file(self.config_file, 'r')) forms = [] users = None @@ -211,7 +209,7 @@ class ScriptForm: users = config['users'] for form in config['forms']: form_name = form['name'] - script = os.path.join(self.basepath, form['script']) + script = form['script'] forms.append( FormDefinition(form_name, form['title'], @@ -313,8 +311,6 @@ class FormConfig: self.log.info("User: {0}".format(getattr(request, 'username', 'None'))) self.log.info("Variables: {0}".format(dict(form_values.items()))) - os.chdir(os.path.dirname(form.script)) - # Pass form values to the script through the environment as strings. env = os.environ.copy() for k, v in form_values.items(): @@ -1122,7 +1118,15 @@ if __name__ == "__main__": parser.error("Insufficient number of arguments") if not options.action_stop and not options.action_start: options.action_start = True - daemon = Daemon(options.pid_file, options.log_file, foreground=options.foreground) + + # If a form configuration was specified, change to that dir so we can + # find the job scripts and such. + if len(args) > 0: + os.chdir(os.path.dirname(args[0])) + args[0] = os.path.basename(args[0]) + + daemon = Daemon(options.pid_file, options.log_file, + foreground=options.foreground) log = logging.getLogger('MAIN') try: if options.action_start: