Simplify directory creation for non-advanced users.

This commit is contained in:
James Vega 2005-04-04 03:15:09 +00:00
parent 3abadc4aec
commit 43bec2808c

View File

@ -120,11 +120,14 @@ def clearLoadedPlugins(plugins, pluginRegistry):
continue continue
_windowsVarRe = re.compile(r'%(\w+)%') _windowsVarRe = re.compile(r'%(\w+)%')
def getDirectoryName(default, basedir=os.curdir): def getDirectoryName(default, basedir=os.curdir, prompt=True):
done = False done = False
while not done: while not done:
if prompt:
dir = something('What directory do you want to use?', dir = something('What directory do you want to use?',
default=os.path.join(basedir, default)) default=os.path.join(basedir, default))
else:
dir = os.path.join(basedir, default)
orig_dir = dir orig_dir = dir
dir = os.path.expanduser(dir) dir = os.path.expanduser(dir)
dir = _windowsVarRe.sub(r'$\1', dir) dir = _windowsVarRe.sub(r'$\1', dir)
@ -138,6 +141,7 @@ def getDirectoryName(default, basedir=os.curdir):
output("""Sorry, I couldn't make that directory for some output("""Sorry, I couldn't make that directory for some
reason. The Operating System told me %s. You're going to reason. The Operating System told me %s. You're going to
have to pick someplace else.""" % e) have to pick someplace else.""" % e)
prompt = True
else: else:
done = True done = True
return (dir, os.path.dirname(orig_dir)) return (dir, os.path.dirname(orig_dir))
@ -202,41 +206,51 @@ def main():
# We set these variables in cache because otherwise conf and log will # We set these variables in cache because otherwise conf and log will
# create directories for the default values, which might not be what the # create directories for the default values, which might not be what the
# user wants. # user wants.
if advanced:
output("""Now we've got to ask you some questions about where some of output("""Now we've got to ask you some questions about where some of
your directories are (or, perhaps, will be :)). If you're running this your directories are (or, perhaps, will be :)). If you're running this
wizard from the directory you'll actually be starting your bot from and wizard from the directory you'll actually be starting your bot from and
don't mind creating some directories in the current directory, then just don't mind creating some directories in the current directory, then
don't give answers to these questions and we'll create the directories we just don't give answers to these questions and we'll create the
need right here in this directory.""") directories we need right here in this directory.""")
# conf.supybot.directories.log # conf.supybot.directories.log
output("""Your bot will need to put his logs somewhere. Do you have any output("""Your bot will need to put his logs somewhere. Do you have
specific place you'd like them? If not, just press enter and we'll make any specific place you'd like them? If not, just press enter and we'll
a directory named "logs" right here.""") make a directory named "logs" right here.""")
(logDir, basedir) = getDirectoryName('logs') (logDir, basedir) = getDirectoryName('logs')
conf.supybot.directories.log.setValue(logDir) conf.supybot.directories.log.setValue(logDir)
# conf.supybot.directories.data # conf.supybot.directories.data
output("""Your bot will need to put various data somewhere. Things like output("""Your bot will need to put various data somewhere. Things
databases, downloaded files, etc. Do you have any specific place you'd like databases, downloaded files, etc. Do you have any specific place
like the bot to put these things? If not, just press enter and we'll make you'd like the bot to put these things? If not, just press enter and
a directory named "data" right here.""") we'll make a directory named "data" right here.""")
(dataDir, basedir) = getDirectoryName('data', basedir=basedir) (dataDir, basedir) = getDirectoryName('data', basedir=basedir)
conf.supybot.directories.data.setValue(dataDir) conf.supybot.directories.data.setValue(dataDir)
# conf.supybot.directories.conf # conf.supybot.directories.conf
output("""Your bot must know where to find his configuration files. It'll output("""Your bot must know where to find his configuration files.
probably only make one or two, but it's gotta have some place to put them. It'll probably only make one or two, but it's gotta have some place to
Where should that place be? If you don't care, just press enter and we'll put them. Where should that place be? If you don't care, just press
make a directory right here named "conf" where it'll store his stuff. """) enter and we'll make a directory right here named "conf" where it'll
store his stuff. """)
(confDir, basedir) = getDirectoryName('conf', basedir=basedir) (confDir, basedir) = getDirectoryName('conf', basedir=basedir)
conf.supybot.directories.conf.setValue(confDir) conf.supybot.directories.conf.setValue(confDir)
# conf.supybot.directories.backup
output("""Your bot must know where to place backups of its conf and
data files. Where should that place be? If you don't care, just press
enter and we'll make a directory right here named "backup" where it'll
store his stuff.""")
(backupDir, basedir) = getDirectoryName('backup', basedir=basedir)
conf.supybot.directories.backup.setValue(backupDir)
# pluginDirs # pluginDirs
output("""Your bot will also need to know where to find his plugins at. output("""Your bot will also need to know where to find his plugins at.
Of course, he already knows where the plugins that he came with are, but Of course, he already knows where the plugins that he came with are,
your own personal plugins that you write for will probably be somewhere but your own personal plugins that you write for will probably be
else.""") somewhere else.""")
pluginDirs = conf.supybot.directories.plugins() pluginDirs = conf.supybot.directories.plugins()
output("""Currently, the bot knows about the following directories:""") output("""Currently, the bot knows about the following directories:""")
output(format('%L', pluginDirs)) output(format('%L', pluginDirs))
@ -247,6 +261,32 @@ def main():
if pluginDir not in pluginDirs: if pluginDir not in pluginDirs:
pluginDirs.append(pluginDir) pluginDirs.append(pluginDir)
conf.supybot.directories.plugins.setValue(pluginDirs) conf.supybot.directories.plugins.setValue(pluginDirs)
else:
output("""Your bot needs to create some directories in order to store
the various log, config, and data files.""")
basedir = something("""Where would you like to create these
directories?""")
# conf.supybot.directories.log
(logDir, basedir) = getDirectoryName('logs', prompt=False)
conf.supybot.directories.log.setValue(logDir)
# conf.supybot.directories.data
(dataDir, basedir) = getDirectoryName('data',
basedir=basedir, prompt=False)
conf.supybot.directories.data.setValue(dataDir)
# conf.supybot.directories.conf
(confDir, basedir) = getDirectoryName('conf',
basedir=basedir, prompt=False)
conf.supybot.directories.conf.setValue(confDir)
# conf.supybot.directories.backup
(backupDir, basedir) = getDirectoryName('backup',
basedir=basedir, prompt=False)
conf.supybot.directories.backup.setValue(backupDir)
# pluginDirs
pluginDirs = conf.supybot.directories.plugins()
(pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
if pluginDir not in pluginDirs:
pluginDirs.append(pluginDir)
conf.supybot.directories.plugins.setValue(pluginDirs)
output("Good! We're done with the directory stuff.") output("Good! We're done with the directory stuff.")