Merge lp:~stefanor/ibid/setup-prompts-515550 into lp:~ibid-core/ibid/old-trunk-1.6

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: not available
Merged at revision: 881
Proposed branch: lp:~stefanor/ibid/setup-prompts-515550
Merge into: lp:~ibid-core/ibid/old-trunk-1.6
Diff against target: 247 lines (+101/-44)
3 files modified
ibid/__init__.py (+1/-1)
ibid/db/__init__.py (+5/-1)
scripts/ibid-setup (+95/-42)
To merge this branch: bzr merge lp:~stefanor/ibid/setup-prompts-515550
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
marcog (community) Approve
Michael Gorven Approve
Ibid Dev Team Pending
Ibid Core Team Pending
Review via email: mp+18699@code.launchpad.net

This proposal supersedes a proposal from 2010-02-03.

To post a comment you must log in.
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

OK, so maybe this fixes more than one thing, but they are all in ibid-setup

Revision history for this message
Michael Gorven (mgorven) wrote : Posted in a previous version of this proposal

 review approve

review: Approve
Revision history for this message
marcog (marco-gallotta) wrote : Posted in a previous version of this proposal

While you're at it, how about making it clearer that what the nick/JID, source and password are? Someone might go choose a totally different nick to their source nick. "source" is quite arb to unaccustomed users. And which password? The one I use on IRC or a new one?

review: Needs Fixing
Revision history for this message
Jonathan Hitchcock (vhata) wrote : Posted in a previous version of this proposal

+1 for Marco's comment.

I would also say something like "Pick a name for your first source" instead of just "Source name" - the latter sounds like something I should know, instead of something that I can make up.

review: Needs Fixing
Revision history for this message
Stefano Rivera (stefanor) wrote : Posted in a previous version of this proposal

> While you're at it, how about making it clearer that what the nick/JID, source
> and password are?

Rereview please.

Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve
875. By Stefano Rivera

Reword account prompt

876. By Stefano Rivera

Reword account password prompt

877. By Stefano Rivera

Unicode everywhere

Revision history for this message
marcog (marco-gallotta) wrote :

Still not so happy about the lack of error-checking which can end in very weird results, e.g.

Database URL [Default: sqlite:///ibid.db]: foo
Traceback (most recent call last):
  File "scripts/ibid-setup", line 97, in <module>
    db = DatabaseManager(check_schema_versions=False)
...
    "Could not parse rfc1738 URL from string '%s'" % name)
sqlalchemy.exceptions.ArgumentError: Could not parse rfc1738 URL from string 'foo'

Source name example of "freenode" suggests that it has to be the server name. Not sure if this is good or bad.

Source type could have a default of IRC.

Mention that non-{irc,jabber} sources can be configured manually, with pointer to docs.

> Couldn't load trac plugin: argument of type 'NoneType' is not iterable

What?

Mask warnings.

Maybe hide the debug output (keeping info) unless -v is passed. Why is "Database tables created" and all the "Couldn't load" stuff not printed as info messages?

review: Needs Fixing
878. By Stefano Rivera

Suppres trac load exception in ibid-setup by having an ibid.databases dict

879. By Stefano Rivera

Raise logging noise floor by default in ibid-setup

880. By Stefano Rivera

Relocate module loading to after config file already exists, and complain less

881. By Stefano Rivera

We only support IRC and jabber

882. By Stefano Rivera

Default to IRC

Revision history for this message
Stefano Rivera (stefanor) wrote :

> Still not so happy about the lack of error-checking which can end in very
> weird results, e.g.

I'm ignoring that for now. It's a new bot install, so you can't do serious damage that can't be fixed with rm -rf. https://bugs.edge.launchpad.net/ibid/+bug/517617

> Source name example of "freenode" suggests that it has to be the server name.
> Not sure if this is good or bad.

Marco changed his mind about this.

> Source type could have a default of IRC.

r882.

> Mention that non-{irc,jabber} sources can be configured manually, with pointer
> to docs.

r881.

> > Couldn't load trac plugin: argument of type 'NoneType' is not iterable

r880.

> Mask warnings.

I'll look at that now.

> Maybe hide the debug output (keeping info) unless -v is passed.

r879.

> Why is "Database tables created" and all the "Couldn't load" stuff not printed as
> info messages?

Because info messages are ugly. The ones you see come from elsewhere in ibid. But it's a plausible change request.

883. By Stefano Rivera

Shush SQLAlchemy save_or_update warnings

Revision history for this message
Stefano Rivera (stefanor) wrote :

> I'll look at that now.

r883.

884. By Stefano Rivera

Merged from trunk

Revision history for this message
marcog (marco-gallotta) wrote :

> > Source type could have a default of IRC.
>
> r882.

Nit-pick, but the default should be specified in [].

> > Mask warnings.
>
> I'll look at that now.

Confirm password:
/var/lib/python-support/python2.6/sqlalchemy/engine/default.py:241: SAWarning: Unicode type received non-unicode bind param value 'a'
  param.append(processors[key](compiled_params[key]))
Account created with admin permissions

review: Needs Fixing
Revision history for this message
Stefano Rivera (stefanor) wrote :

> Nit-pick, but the default should be specified in [].

r885.

> Confirm password:
> /var/lib/python-support/python2.6/sqlalchemy/engine/default.py:241: SAWarning:
> Unicode type received non-unicode bind param value 'a'
> param.append(processors[key](compiled_params[key]))

r886.

885. By Stefano Rivera

Make it clear that IRC is default

886. By Stefano Rivera

Helper function to decode all input to unicode

Revision history for this message
marcog (marco-gallotta) :
review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) wrote :

I'm hoping #515550 will make this even greaterer, but this is good for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/__init__.py'
2--- ibid/__init__.py 2010-01-31 15:38:34 +0000
3+++ ibid/__init__.py 2010-02-05 19:55:18 +0000
4@@ -84,7 +84,7 @@
5 dispatcher = None
6 processors = []
7 reloader = None
8-databases = None
9+databases = {}
10 auth = None
11 service = None
12 options = {}
13
14=== modified file 'ibid/db/__init__.py'
15--- ibid/db/__init__.py 2010-02-03 16:06:30 +0000
16+++ ibid/db/__init__.py 2010-02-05 19:55:18 +0000
17@@ -1,5 +1,6 @@
18 # Copyright (c) 2009-2010, Stefano Rivera
19 # Released under terms of the MIT/X/Expat Licence. See COPYING for details.
20+import warnings as _warnings
21
22 from ibid.db.types import TypeDecorator, Integer, DateTime, Boolean, \
23 IbidUnicode, IbidUnicodeText
24@@ -10,7 +11,7 @@
25 from sqlalchemy.sql import func
26 from sqlalchemy.ext.declarative import declarative_base as _declarative_base
27
28-from sqlalchemy.exceptions import IntegrityError
29+from sqlalchemy.exceptions import IntegrityError, SADeprecationWarning
30
31 metadata = _MetaData()
32 Base = _declarative_base(metadata=metadata)
33@@ -18,4 +19,7 @@
34 from ibid.db.versioned_schema import VersionedSchema, SchemaVersionException, \
35 schema_version_check, upgrade_schemas
36
37+# We use SQLAlchemy 0.4 compatible .save_or_update() functions
38+_warnings.filterwarnings('ignore', 'Use session.add\(\)', SADeprecationWarning)
39+
40 # vi: set et sta sw=4 ts=4:
41
42=== modified file 'scripts/ibid-setup'
43--- scripts/ibid-setup 2010-01-18 22:13:23 +0000
44+++ scripts/ibid-setup 2010-02-05 19:55:18 +0000
45@@ -3,15 +3,15 @@
46 # Released under terms of the MIT/X/Expat Licence. See COPYING for details.
47
48 import logging
49+from optparse import OptionParser
50 import sys
51 from sys import exit, stderr
52-from sqlalchemy import create_engine
53-from sqlalchemy.orm import sessionmaker
54 from getpass import getpass
55+from os import getenv
56 from os.path import exists
57 from shutil import copyfileobj
58
59-from pkg_resources import resource_stream
60+from pkg_resources import resource_filename, resource_stream
61 from twisted.python.modules import getModule
62
63 sys.path.insert(0, '.')
64@@ -19,76 +19,128 @@
65 import ibid
66 from ibid.config import FileConfig
67 from ibid.core import DatabaseManager
68-from ibid.db import metadata, upgrade_schemas
69+from ibid.db import upgrade_schemas
70 from ibid.db.models import Account, Identity, Permission, Credential
71 from ibid.auth import hash
72
73-logging.basicConfig(level=logging.DEBUG)
74-
75-for module in getModule('ibid.plugins').iterModules():
76- try:
77- __import__(module.name)
78- except Exception, e:
79- print >> stderr, u"Couldn't load %s plugin: %s" % (module.name.replace('ibid.plugins.', ''), unicode(e))
80+parser = OptionParser(usage="%prog [options...]")
81+parser.add_option('-v', '--verbose', action='store_true', default=False,
82+ help="Output debugging information")
83+
84+(options, args) = parser.parse_args()
85+
86+if options.verbose:
87+ logging.basicConfig(level=logging.DEBUG)
88+else:
89+ logging.basicConfig(level=logging.INFO)
90+
91+try:
92+ encoding = getenv("LANG").split(".")[1]
93+except:
94+ encoding = "ascii"
95+
96+def prompt(prompt, secret=False):
97+ if secret:
98+ r = getpass(prompt)
99+ else:
100+ r = raw_input(prompt)
101+ return unicode(r, encoding)
102
103 ibid.options = {'base': '.'}
104 if exists('ibid.ini'):
105 ibid.config = FileConfig('ibid.ini')
106 ibid.config.merge(FileConfig('local.ini'))
107 sname = None
108-
109 else:
110- sample_config = resource_stream('ibid', 'config.ini')
111+ sample_config = resource_filename('ibid', 'config.ini')
112 ibid.config = FileConfig(sample_config)
113
114- botname = raw_input(u'What would you like to call your bot? ')
115+ botname = prompt(u'\nWhat would you like to call your bot? ')
116 ibid.config['botname'] = botname
117
118- print u'Please enter the full URL of the database to use, or just press Enter for an SQLite database.'
119- ibid.config.databases['ibid'] = raw_input(u'Database URL: ') or 'sqlite:///ibid.db'
120-
121- print u"Please enter the details for the primary source. Press Enter for the default option."
122+print u'Loading plugins...'
123+for module in getModule('ibid.plugins').iterModules():
124+ try:
125+ __import__(module.name)
126+ except Exception, e:
127+ if options.verbose:
128+ print >> stderr, u"Couldn't load %s plugin: %s" % (
129+ module.name.replace('ibid.plugins.', ''), unicode(e))
130+
131+if not exists('ibid.ini'):
132+ print u"""
133+Database configuration:
134+If you want to use the default SQLite database, just press Enter.
135+Otherwise please enter a SQLAlchemy database URL.
136+Supported databases:
137+* mysql://user:pass@host/database
138+* postgres://user:pass@host/database (load the CITEXT contrib module first)
139+* sqlite:///filename"""
140+ ibid.config.databases['ibid'] = prompt(
141+ u'Database URL [Default: sqlite:///ibid.db]: '
142+ ) or 'sqlite:///ibid.db'
143+
144+ print u"""
145+Source configuration:
146+Your bot needs to connect to an IM service (in Ibid terminology, a source) like
147+an IRC server or jabber account. Please enter the details for the primary
148+source.
149+Note: This setup script currently only supports IRC and jabber. You can set up
150+other sources manually in ibid.ini.
151+
152+The source name should be the IRC network name or a generic description for the
153+source like 'jabber'.
154+"""
155 source = {'nick': '$botname'}
156- sname = raw_input(u'Source name (e.g. freenode, atrum, jabber): ')
157- source['server'] = raw_input(u'Server: ')
158- port = raw_input(u'Port: ')
159- if port:
160- source['port'] = port
161- source['type'] = raw_input(u'Source type (irc or jabber): ')
162+ sname = prompt(u'Source name (e.g. freenode, jabber): ')
163+ source['type'] = prompt(u'Source type (irc, jabber) [Default: irc]: ')
164
165- if source['type'].lower() == 'irc':
166- source['channels'] = [c.strip() for c in raw_input(u'Default channels to join (comma separated): ').split(',')]
167+ if source['type'].lower() in (u'irc', u''):
168+ source['server'] = prompt(u'IRC Server: ')
169+ port = prompt(u'Port [Default: 6667]: ')
170+ if port:
171+ source['port'] = port
172+ source['channels'] = [c.strip() for c in prompt(
173+ u'Channels to join (comma separated) [Default: none]: '
174+ ).split(u',')]
175 source['auth'] = ['hostmask', 'nickserv']
176- elif source['type'].lower() == 'jabber':
177- source['jid'] = raw_input(u'JID: ')
178- source['password'] = getpass(u'Password: ')
179- source['rooms'] = [r.strip() for r in raw_input(u'Default rooms to join (comma separated): ').split(',')]
180+ elif source['type'].lower() == u'jabber':
181+ source['jid'] = prompt(u'JID (Jabber address): ')
182+ source['password'] = prompt(u'Password: ', secret=True)
183+ source['rooms'] = [r.strip() for r in prompt(
184+ u'MUC rooms to join (comma separated) [Default: none]: '
185+ ).split(u',')]
186 source['auth'] = ['implicit']
187- source['ssl'] = raw_input(u'SSL (Y/N): ').lower() in ('y', 'yes', 'true')
188 else:
189- print 'Invalid source type'
190+ print u'Invalid source type.'
191 exit(1)
192
193 ibid.config.sources[sname] = source
194
195 ibid.config.write(open('ibid.ini', 'w'))
196 if not exists('logging.ini'):
197- copyfileobj(resource_stream('ibid', 'logging.ini'), open('logging.ini', 'w'))
198+ copyfileobj(resource_stream('ibid', 'logging.ini'),
199+ open('logging.ini', 'w'))
200
201 db = DatabaseManager(check_schema_versions=False)
202 Session = db['ibid']
203 upgrade_schemas(Session)
204
205-print u'Database tables created'
206+print u"""Database tables created
207
208-print u'Please enter the details for your account. This account will be given full admin permissions.'
209-identity = unicode(raw_input('Nick/JID: '))
210-source = sname or unicode(raw_input('Source name: '))
211-pass1 = getpass('Password: ')
212-pass2 = getpass('Confirm password: ')
213+Now we need to create an account for you in the bot so it knows who its
214+master is. This account will be given full admin permissions.
215+Please enter the details for your account."""
216+identity = prompt(u'Your IRC Nick/Jabber ID: ')
217+if not identity:
218+ print u'Skipping account creation'
219+ exit(0)
220+source = sname or prompt(u'Source name: ')
221+pass1 = prompt(u'Password to identify yourself to the bot: ', secret=True)
222+pass2 = prompt(u'Confirm password: ', secret=True)
223
224 if pass1 != pass2:
225- print 'Password do not match'
226+ print u'Password do not match'
227 exit(1)
228
229 session = Session()
230@@ -97,7 +149,8 @@
231 account.identities.append(identity)
232
233 for permission in (u'accounts', u'sources', u'plugins', u'core', u'admin',
234- u'config', u'saydo', u'factoidadmin', u'karmaadmin', u'eval'):
235+ u'config', u'saydo', u'factoidadmin', u'karmaadmin', u'eval',
236+ u'chairmeeting'):
237 perm = Permission(permission, u'auth')
238 account.permissions.append(perm)
239
240@@ -109,6 +162,6 @@
241 session.commit()
242 session.close()
243
244-print 'Account created with admin permissions'
245+print u'Account created with admin permissions'
246
247 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches