Change dir to form config directory in main method, not in a class.

pull/7/head
Ferry Boender 10 years ago
parent fb77cd7a7a
commit 51be118f85
  1. 18
      src/scriptform.py

@ -187,7 +187,6 @@ class ScriptForm:
def __init__(self, config_file, cache=True): def __init__(self, config_file, cache=True):
self.config_file = config_file self.config_file = config_file
self.cache = cache self.cache = cache
self.basepath = os.path.realpath(os.path.dirname(config_file))
self.log = logging.getLogger('SCRIPTFORM') self.log = logging.getLogger('SCRIPTFORM')
self.get_form_config() # Init form config so it can raise errors about problems. self.get_form_config() # Init form config so it can raise errors about problems.
self.websrv = None self.websrv = None
@ -201,8 +200,7 @@ class ScriptForm:
if self.cache and hasattr(self, 'form_config_singleton'): if self.cache and hasattr(self, 'form_config_singleton'):
return self.form_config_singleton return self.form_config_singleton
path = self.config_file config = json.load(file(self.config_file, 'r'))
config = json.load(file(path, 'r'))
forms = [] forms = []
users = None users = None
@ -211,7 +209,7 @@ class ScriptForm:
users = config['users'] users = config['users']
for form in config['forms']: for form in config['forms']:
form_name = form['name'] form_name = form['name']
script = os.path.join(self.basepath, form['script']) script = form['script']
forms.append( forms.append(
FormDefinition(form_name, FormDefinition(form_name,
form['title'], form['title'],
@ -313,8 +311,6 @@ class FormConfig:
self.log.info("User: {0}".format(getattr(request, 'username', 'None'))) self.log.info("User: {0}".format(getattr(request, 'username', 'None')))
self.log.info("Variables: {0}".format(dict(form_values.items()))) 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. # Pass form values to the script through the environment as strings.
env = os.environ.copy() env = os.environ.copy()
for k, v in form_values.items(): for k, v in form_values.items():
@ -1122,7 +1118,15 @@ if __name__ == "__main__":
parser.error("Insufficient number of arguments") parser.error("Insufficient number of arguments")
if not options.action_stop and not options.action_start: if not options.action_stop and not options.action_start:
options.action_start = True 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') log = logging.getLogger('MAIN')
try: try:
if options.action_start: if options.action_start:

Loading…
Cancel
Save