Skip to content

Commit

Permalink
removing unused config parsers
Browse files Browse the repository at this point in the history
removed both localParser and globalParser. also removed write and set()
functions. Assuming they're holdovers from the web gui psiturk version
(pre-shell days).
  • Loading branch information
deargle committed Feb 27, 2017
1 parent a8345d1 commit 8bb0740
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions psiturk/psiturk_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ def __init__(self, localConfig="config.txt", globalConfigName=".psiturkconfig",
self.parent.__init__(self, **kwargs)
self.localFile = localConfig
self.globalFile = os.path.expanduser(globalConfig)
# psiturkConfig contains two additional SafeConfigParser's holding the values
# of the local and global config files. This lets us write to the local or global file
# separately without writing all fields to both.
self.localParser = self.parent(**kwargs)
self.globalParser = self.parent(**kwargs)

def load_config(self):
defaults_folder = os.path.join(os.path.dirname(__file__), "default_configs")
Expand All @@ -30,7 +25,6 @@ def load_config(self):
if not os.path.exists(self.localFile):
print "ERROR - no config.txt file in the current directory. \n\nAre you sure this directory is a valid psiTurk experiment? If you are starting a new project run 'psiturk-setup-example' first."
exit()
self.localParser.read( self.localFile)
if not os.path.exists(self.globalFile):
if 'OPENSHIFT_SECRET_TOKEN' in os.environ:
print "No '.psiturkconfig' file found in your " + os.environ['OPENSHIFT_DATA_DIR'] + " directory.\nCreating default " + self.globalFile + " file."
Expand All @@ -39,36 +33,8 @@ def load_config(self):
else:
print "No '.psiturkconfig' file found in your home directory.\nCreating default ~/.psiturkconfig file."
file_util.copy_file(global_defaults_file, self.globalFile)
self.globalParser.read(self.globalFile)
# read default global and local, then user's global and local. This way
# any field not in the user's files will be set to the default value.
self.read([global_defaults_file, local_defaults_file, self.globalFile, self.localFile])

def write(self, changeGlobal=False):
"""
write to the user's global or local config file.
"""
filename = self.localFile
configObject = self.localParser
if changeGlobal:
filename = self.globalFile
configObject = self.globalParser
with open(filename, 'w') as fp:
configObject.write(fp)

def set(self, section, field, value, changeGlobal=False, *args, **kwargs):
"""
Set the given field in the given section to the given value.
Return True if the server needs to be rebooted.
"""
self.parent.set(self, section, field, str(value), *args, **kwargs)
if changeGlobal:
self.globalParser.set(section, field, str(value), *args, **kwargs)
else:
self.localParser.set(section, field, str(value), *args, **kwargs)
self.write(changeGlobal)
if section in ["Server Parameters","Task Parameters","Database Parameters"]:
return True
else:
return False


0 comments on commit 8bb0740

Please sign in to comment.