Update of /cvsroot/webware/Webware
In directory usw-pr-cvs1:/tmp/cvs-serv4058
Modified Files:
install.py
Log Message:
Adding password options to install.py
Index: install.py
===================================================================
RCS file: /cvsroot/webware/Webware/install.py,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** install.py 2 Mar 2002 15:42:14 -0000 1.35
--- install.py 9 Mar 2002 17:44:37 -0000 1.36
***************
*** 47,51 ****
## Running the installation ##
! def run(self, verbose=0):
self._verbose = verbose
if self._verbose: self.printMsg = self._printMsg
--- 47,51 ----
## Running the installation ##
! def run(self, verbose=0, passprompt=1, defaultpass=''):
self._verbose = verbose
if self._verbose: self.printMsg = self._printMsg
***************
*** 59,62 ****
--- 59,63 ----
self.compileModules()
self.fixPermissions()
+ self.setupWebKitPassword(passprompt, defaultpass)
self.finished()
self.printGoodbye()
***************
*** 126,129 ****
--- 127,201 ----
self._comps.sort(lambda a, b: cmp(a['name'], b['name']))
+
+ def setupWebKitPassword(self, prompt, defpass):
+ ''' Setup a password for WebKit Application server. '''
+ print 'Setting passwords...'
+ print
+
+ password = ''
+ if defpass:
+ if prompt:
+ print 'Choose a Password for WebKit Application Server.'
+ print 'If you will just press enter without entering anything,'
+ print 'the password specified on the command-line will be used;'
+ print 'you can check the password after installation at:'
+ print 'WebKit/Configs/Application.config'
+ import getpass
+ password = getpass.getpass()
+ else:
+ print 'A password was specified on the command-line; check'
+ print 'the file: WebKit/Configs/Application.config'
+ print 'after installation for the password'
+
+ if len(password) == 0:
+ password = defpass
+ else:
+ if prompt:
+ print 'Choose a Password for WebKit Application Server.'
+ print 'If you will just press enter without entering anything'
+ print 'a random password will be generated; you can check the password'
+ print 'after installation at: WebKit/Configs/Application.config'
+ import getpass
+ password = getpass.getpass()
+ else:
+ print 'A password was autogenerated; check the file: ',
+ print 'WebKit/Configs/Application.config'
+ print 'after installation for the password'
+
+ if len(password) == 0:
+ # Generate 7 digits worth of a password.
+ # The random function gives back a real number.
+ characters = string.letters + string.digits
+
+ import whrandom
+ for i in range(8):
+ password = password + whrandom.choice(characters)
+
+ try:
+ data = open('WebKit/Configs/Application.config', 'r').read()
+ except IOError:
+ print 'Error reading config file, possibly a permission problem,'
+ print 'password not replaced, make sure to edit it by hand.'
+ return
+
+ # This will search for the construct:
+ # 'AdminPassword': 'password'
+ # and replace whatever password is written there with what is
+ # given in the 'password' variable.
+ pattern = "('AdminPassword'\s*:)\s*'.*?'"
+ repl = "\g<1>\t'%s'" % (password,)
+ import re
+ # Still need to verify that we actually found a match!
+ data = re.sub(pattern, repl, data)
+
+ try:
+ open('WebKit/Configs/Application.config', 'w').write(data)
+ except IOError:
+ print 'Error writing config file, possibly a permission problem,'
+ print 'password not replaced, make sure to edit it by hand.'
+ return
+
+ print 'Password replaced successfully.'
+
def installDocs(self):
self.propagateStyleSheet()
***************
*** 444,452 ****
if __name__=='__main__':
! import sys, getopt
verbose=0
! opts, args = getopt.getopt(sys.argv[1:], "v")
! for o, a in opts:
! if o in ("-v", ): verbose=1
! Installer().run(verbose=verbose)
--- 516,553 ----
+ def printHelp():
+ print 'Usage: install.py [options]'
+ print 'Install WebWare in the local directory.'
+ print
+ print ' -h, --help This help screen'
+ print ' -v, --verbose Print extra information messages during install'
+ print ' --password-prompt=yes/no Do not prompt for password during install'
+ print ' Will autogenerate a random password'
+ print ' --set-password=password Set the password, if you follow it with'
+ print ' --password-prompt=yes it will be used as a default'
+
if __name__=='__main__':
! import getopt
verbose=0
! passprompt=1
! defaultpass=''
! try:
! opts, args = getopt.getopt(sys.argv[1:], "hv", ["help", "verbose", "password-prompt=", "set-password="])
! except getopt.GetoptError:
! printHelp()
! else:
! for o, a in opts:
! if o in ("-v", "--verbose"): verbose=1
! if o in ("--password-prompt",):
! if a in ("1", "yes", "true"):
! passprompt=1
! elif a in ("0", "no", "false"):
! passprompt=0
! if o in ("--set-password",):
! defaultpass=a
! passprompt=0
! if o in ("-h", "--help"):
! printHelp()
! sys.exit(0)
!
! Installer().run(verbose=verbose, passprompt=passprompt, defaultpass=defaultpass)
|