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
1 changed files with 81 additions and 41 deletions

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:
dir = something('What directory do you want to use?', if prompt:
default=os.path.join(basedir, default)) dir = something('What directory do you want to use?',
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,51 +206,87 @@ 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.
output("""Now we've got to ask you some questions about where some of if advanced:
your directories are (or, perhaps, will be :)). If you're running this output("""Now we've got to ask you some questions about where some of
wizard from the directory you'll actually be starting your bot from and your directories are (or, perhaps, will be :)). If you're running this
don't mind creating some directories in the current directory, then just wizard from the directory you'll actually be starting your bot from and
don't give answers to these questions and we'll create the directories we don't mind creating some directories in the current directory, then
need right here in this directory.""") just don't give answers to these questions and we'll create the
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
(confDir, basedir) = getDirectoryName('conf', basedir=basedir) store his stuff. """)
conf.supybot.directories.conf.setValue(confDir) (confDir, basedir) = getDirectoryName('conf', basedir=basedir)
conf.supybot.directories.conf.setValue(confDir)
# pluginDirs # conf.supybot.directories.backup
output("""Your bot will also need to know where to find his plugins at. output("""Your bot must know where to place backups of its conf and
Of course, he already knows where the plugins that he came with are, but data files. Where should that place be? If you don't care, just press
your own personal plugins that you write for will probably be somewhere enter and we'll make a directory right here named "backup" where it'll
else.""") store his stuff.""")
pluginDirs = conf.supybot.directories.plugins() (backupDir, basedir) = getDirectoryName('backup', basedir=basedir)
output("""Currently, the bot knows about the following directories:""") conf.supybot.directories.backup.setValue(backupDir)
output(format('%L', pluginDirs))
while yn('Would you like to add another plugin directory? ' # pluginDirs
'Adding a local plugin directory is good style.', output("""Your bot will also need to know where to find his plugins at.
default=True): Of course, he already knows where the plugins that he came with are,
but your own personal plugins that you write for will probably be
somewhere else.""")
pluginDirs = conf.supybot.directories.plugins()
output("""Currently, the bot knows about the following directories:""")
output(format('%L', pluginDirs))
while yn('Would you like to add another plugin directory? '
'Adding a local plugin directory is good style.',
default=True):
(pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
if pluginDir not in pluginDirs:
pluginDirs.append(pluginDir)
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) (pluginDir, _) = getDirectoryName('plugins', basedir=basedir)
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)
output("Good! We're done with the directory stuff.") output("Good! We're done with the directory stuff.")