confwiz: add command line options

adds command line option parsing to the confwiz.

the previous --uninstall option behaves as before, but it parsed
more explicitly with the twisted usage library.

added is a --server option, which controls which web site the
backend script for configuration is to be found on. (it is looked
for at /native_client.php on the given server) this option can be
used on conjunction with --uninstall to control where the uninstall
is recorded

Options:
  -u, --uninstall  record uninstall
  -s, --server=    url of server to contact 
                   [default: https://beta.allmydata.com/]

e.g. confwiz.py -s https://www-test.allmydata.com/
This commit is contained in:
robk-tahoe 2008-02-14 19:44:29 -07:00
parent 72874390fe
commit 78c53b81ec
2 changed files with 60 additions and 29 deletions

View File

@ -1,6 +1,8 @@
BACKEND_URL = 'https://beta.allmydata.com/native_client.php' DEFAULT_SERVER_URL = 'https://beta.allmydata.com/'
ACCOUNT_PAGE = 'https://beta.allmydata.com/account'
BACKEND = 'native_client.php'
ACCOUNT_PAGE = 'account'
TAHOESVC_NAME = 'Tahoe' TAHOESVC_NAME = 'Tahoe'
WINFUSESVC_NAME = 'Allmydata Tahoe SMB' WINFUSESVC_NAME = 'Allmydata Tahoe SMB'
@ -20,6 +22,7 @@ from allmydata import uri
import amdicon import amdicon
import foolscap import foolscap
from twisted.python import usage
class AuthError(Exception): class AuthError(Exception):
pass pass
@ -111,9 +114,9 @@ def get_nodeid():
tub = foolscap.Tub(certFile=certfile) tub = foolscap.Tub(certFile=certfile)
return tub.getTubID() return tub.getTubID()
def configure(user, passwd): def configure(backend, user, passwd):
_config_re = re.compile('^([^:]*): (.*)$') _config_re = re.compile('^([^:]*): (.*)$')
config = get_config(BACKEND_URL, user, passwd) config = get_config(backend, user, passwd)
config_dict = {} config_dict = {}
for line in config.split('\n'): for line in config.split('\n'):
if line: if line:
@ -143,9 +146,13 @@ def DisplayTraceback(message):
wx.MessageBox(u"%s\n (%s)"%(message,''.join(xc)), 'Error') wx.MessageBox(u"%s\n (%s)"%(message,''.join(xc)), 'Error')
class ConfWizApp(wx.App): class ConfWizApp(wx.App):
def __init__(self): def __init__(self, server):
self.server = server
wx.App.__init__(self, 0) wx.App.__init__(self, 0)
def get_backend(self):
return self.server + BACKEND
def OnInit(self): def OnInit(self):
try: try:
wx.InitAllImageHandlers() wx.InitAllImageHandlers()
@ -182,7 +189,7 @@ class LoginFrame(wx.Frame):
background = wx.Panel(self, -1) background = wx.Panel(self, -1)
background.SetSizeHints(500, 360, 600, 800) background.SetSizeHints(500, 360, 600, 800)
background.parent = self background.parent = self
self.login_panel = LoginPanel(background) self.login_panel = LoginPanel(background, app)
self.reg_btn_panel = RegisterButtonPanel(background, app) self.reg_btn_panel = RegisterButtonPanel(background, app)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
background_sizer = wx.BoxSizer(wx.VERTICAL) background_sizer = wx.BoxSizer(wx.VERTICAL)
@ -212,7 +219,7 @@ class RegisterFrame(wx.Frame):
background = wx.Panel(self, -1) background = wx.Panel(self, -1)
background.SetSizeHints(500, 360, 600, 800) background.SetSizeHints(500, 360, 600, 800)
background.parent = self background.parent = self
self.register_panel = RegisterPanel(background) self.register_panel = RegisterPanel(background, app)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
background_sizer = wx.BoxSizer(wx.VERTICAL) background_sizer = wx.BoxSizer(wx.VERTICAL)
background_sizer.Add(wx.Size(2,2), 10, wx.EXPAND | wx.ALL, 26) background_sizer.Add(wx.Size(2,2), 10, wx.EXPAND | wx.ALL, 26)
@ -231,9 +238,10 @@ class RegisterFrame(wx.Frame):
class LoginPanel(wx.Panel): class LoginPanel(wx.Panel):
def __init__(self, parent): def __init__(self, parent, app):
wx.Panel.__init__(self, parent, -1) wx.Panel.__init__(self, parent, -1)
self.parent = parent self.parent = parent
self.app = app
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
@ -278,6 +286,8 @@ class LoginPanel(wx.Panel):
self.Layout() self.Layout()
wx.Yield() wx.Yield()
backend = self.app.get_backend()
if passwd == '': if passwd == '':
self.warning_label.SetLabel('You must enter a password') self.warning_label.SetLabel('You must enter a password')
self.pass_field.SetFocus() self.pass_field.SetFocus()
@ -285,7 +295,7 @@ class LoginPanel(wx.Panel):
return return
try: try:
root_cap = get_root_cap(BACKEND_URL, user, passwd) root_cap = get_root_cap(backend, user, passwd)
write_config_file('private/root_dir.cap', root_cap+'\n') write_config_file('private/root_dir.cap', root_cap+'\n')
except AuthError: except AuthError:
self.warning_label.SetLabel('Your email and/or password is incorrect') self.warning_label.SetLabel('Your email and/or password is incorrect')
@ -294,11 +304,11 @@ class LoginPanel(wx.Panel):
return return
nodeid = get_nodeid() nodeid = get_nodeid()
ret = record_install(BACKEND_URL, user, passwd, nodeid) ret = record_install(backend, user, passwd, nodeid)
if ret != 'ok': if ret != 'ok':
wx.MessageBox('Error "%s" recording this system (%s)' % (ret, nodeid), 'Error') wx.MessageBox('Error "%s" recording this system (%s)' % (ret, nodeid), 'Error')
configure(user, passwd) configure(backend, user, passwd)
maybe_start_services() maybe_start_services()
# exit # exit
@ -326,9 +336,10 @@ class RegisterButtonPanel(wx.Panel):
self.app.swap_to_register_frame() self.app.swap_to_register_frame()
class RegisterPanel(wx.Panel): class RegisterPanel(wx.Panel):
def __init__(self, parent): def __init__(self, parent, app):
wx.Panel.__init__(self, parent, -1) wx.Panel.__init__(self, parent, -1)
self.parent = parent self.parent = parent
self.app = app
self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer = wx.BoxSizer(wx.VERTICAL)
@ -404,14 +415,16 @@ class RegisterPanel(wx.Panel):
self.Layout() self.Layout()
return return
backend = self.app.get_backend()
#print 'calling create_account', time.asctime() #print 'calling create_account', time.asctime()
result_code = create_account(BACKEND_URL, user, passwd, subscribe) result_code = create_account(backend, user, passwd, subscribe)
if result_code == 'account_exists': if result_code == 'account_exists':
# try and log into it; if valid, use it anyway # try and log into it; if valid, use it anyway
try: try:
#print 'calling get_root_cap (ae)', time.asctime() #print 'calling get_root_cap (ae)', time.asctime()
root_cap = get_root_cap(BACKEND_URL, user, passwd) root_cap = get_root_cap(backend, user, passwd)
write_config_file('private/root_dir.cap', root_cap+'\n') write_config_file('private/root_dir.cap', root_cap+'\n')
except AuthError: except AuthError:
self.warning_label.SetLabel('That email address is already registered') self.warning_label.SetLabel('That email address is already registered')
@ -425,7 +438,7 @@ class RegisterPanel(wx.Panel):
return return
elif result_code == 'ok': elif result_code == 'ok':
#print 'calling get_root_cap (ok)', time.asctime() #print 'calling get_root_cap (ok)', time.asctime()
root_cap = get_root_cap(BACKEND_URL, user, passwd) root_cap = get_root_cap(backend, user, passwd)
write_config_file('private/root_dir.cap', root_cap+'\n') write_config_file('private/root_dir.cap', root_cap+'\n')
else: else:
self.warning_label.SetLabel('an unexpected error occurred ("%s")' % (result_code,)) self.warning_label.SetLabel('an unexpected error occurred ("%s")' % (result_code,))
@ -434,28 +447,50 @@ class RegisterPanel(wx.Panel):
return return
nodeid = get_nodeid() nodeid = get_nodeid()
ret = record_install(BACKEND_URL, user, passwd, nodeid) ret = record_install(backend, user, passwd, nodeid)
if ret != 'ok': if ret != 'ok':
wx.MessageBox('Error "%s" recording this system (%s)' % (ret, nodeid), 'Error') wx.MessageBox('Error "%s" recording this system (%s)' % (ret, nodeid), 'Error')
configure(user, passwd) configure(backend, user, passwd)
maybe_start_services() maybe_start_services()
# exit # exit
self.parent.parent.Close() self.parent.parent.Close()
def do_uninstall(): def do_uninstall(server_url):
nodeid = get_nodeid() nodeid = get_nodeid()
ret = record_uninstall(BACKEND_URL, nodeid) ret = record_uninstall(server_url + BACKEND, nodeid)
print ret print ret
if ret != 'ok': if ret != 'ok':
print 'Error "%s" recording uninstall of this system (%s)' % (ret, nodeid) print 'Error "%s" recording uninstall of this system (%s)' % (ret, nodeid)
class Options(usage.Options):
synopsis = "Usage: confwiz [options]"
optFlags = [
['uninstall', 'u', 'record uninstall'],
]
optParameters = [
['server', 's', DEFAULT_SERVER_URL, 'url of server to contact'],
]
def main(argv): def main(argv):
if '--uninstall' in argv: config = Options()
do_uninstall() try:
config.parseOptions(argv[1:])
except usage.error, e:
print config
print "%s: %s" % (sys.argv[0], e)
sys.exit(-1)
server = config['server']
if not server.endswith('/'):
server += '/'
if config['uninstall']:
do_uninstall(server)
else: else:
app = ConfWizApp() app = ConfWizApp(server)
app.MainLoop() app.MainLoop()

View File

@ -1,9 +1,5 @@
import sys
from allmydata.gui.confwiz import ConfWizApp from allmydata.gui.confwiz import main
def main():
app = ConfWizApp()
app.MainLoop()
if __name__ == '__main__': if __name__ == '__main__':
main() main(sys.argv)