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
=== modified file 'ibid/__init__.py'
--- ibid/__init__.py 2010-01-31 15:38:34 +0000
+++ ibid/__init__.py 2010-02-05 19:55:18 +0000
@@ -84,7 +84,7 @@
84dispatcher = None84dispatcher = None
85processors = []85processors = []
86reloader = None86reloader = None
87databases = None87databases = {}
88auth = None88auth = None
89service = None89service = None
90options = {}90options = {}
9191
=== modified file 'ibid/db/__init__.py'
--- ibid/db/__init__.py 2010-02-03 16:06:30 +0000
+++ ibid/db/__init__.py 2010-02-05 19:55:18 +0000
@@ -1,5 +1,6 @@
1# Copyright (c) 2009-2010, Stefano Rivera1# Copyright (c) 2009-2010, Stefano Rivera
2# Released under terms of the MIT/X/Expat Licence. See COPYING for details.2# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
3import warnings as _warnings
34
4from ibid.db.types import TypeDecorator, Integer, DateTime, Boolean, \5from ibid.db.types import TypeDecorator, Integer, DateTime, Boolean, \
5 IbidUnicode, IbidUnicodeText6 IbidUnicode, IbidUnicodeText
@@ -10,7 +11,7 @@
10from sqlalchemy.sql import func11from sqlalchemy.sql import func
11from sqlalchemy.ext.declarative import declarative_base as _declarative_base12from sqlalchemy.ext.declarative import declarative_base as _declarative_base
1213
13from sqlalchemy.exceptions import IntegrityError14from sqlalchemy.exceptions import IntegrityError, SADeprecationWarning
1415
15metadata = _MetaData()16metadata = _MetaData()
16Base = _declarative_base(metadata=metadata)17Base = _declarative_base(metadata=metadata)
@@ -18,4 +19,7 @@
18from ibid.db.versioned_schema import VersionedSchema, SchemaVersionException, \19from ibid.db.versioned_schema import VersionedSchema, SchemaVersionException, \
19 schema_version_check, upgrade_schemas20 schema_version_check, upgrade_schemas
2021
22# We use SQLAlchemy 0.4 compatible .save_or_update() functions
23_warnings.filterwarnings('ignore', 'Use session.add\(\)', SADeprecationWarning)
24
21# vi: set et sta sw=4 ts=4:25# vi: set et sta sw=4 ts=4:
2226
=== modified file 'scripts/ibid-setup'
--- scripts/ibid-setup 2010-01-18 22:13:23 +0000
+++ scripts/ibid-setup 2010-02-05 19:55:18 +0000
@@ -3,15 +3,15 @@
3# Released under terms of the MIT/X/Expat Licence. See COPYING for details.3# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
44
5import logging5import logging
6from optparse import OptionParser
6import sys7import sys
7from sys import exit, stderr8from sys import exit, stderr
8from sqlalchemy import create_engine
9from sqlalchemy.orm import sessionmaker
10from getpass import getpass9from getpass import getpass
10from os import getenv
11from os.path import exists11from os.path import exists
12from shutil import copyfileobj12from shutil import copyfileobj
1313
14from pkg_resources import resource_stream14from pkg_resources import resource_filename, resource_stream
15from twisted.python.modules import getModule15from twisted.python.modules import getModule
1616
17sys.path.insert(0, '.')17sys.path.insert(0, '.')
@@ -19,76 +19,128 @@
19import ibid19import ibid
20from ibid.config import FileConfig20from ibid.config import FileConfig
21from ibid.core import DatabaseManager21from ibid.core import DatabaseManager
22from ibid.db import metadata, upgrade_schemas22from ibid.db import upgrade_schemas
23from ibid.db.models import Account, Identity, Permission, Credential23from ibid.db.models import Account, Identity, Permission, Credential
24from ibid.auth import hash24from ibid.auth import hash
2525
26logging.basicConfig(level=logging.DEBUG)26parser = OptionParser(usage="%prog [options...]")
2727parser.add_option('-v', '--verbose', action='store_true', default=False,
28for module in getModule('ibid.plugins').iterModules():28 help="Output debugging information")
29 try:29
30 __import__(module.name)30(options, args) = parser.parse_args()
31 except Exception, e:31
32 print >> stderr, u"Couldn't load %s plugin: %s" % (module.name.replace('ibid.plugins.', ''), unicode(e))32if options.verbose:
33 logging.basicConfig(level=logging.DEBUG)
34else:
35 logging.basicConfig(level=logging.INFO)
36
37try:
38 encoding = getenv("LANG").split(".")[1]
39except:
40 encoding = "ascii"
41
42def prompt(prompt, secret=False):
43 if secret:
44 r = getpass(prompt)
45 else:
46 r = raw_input(prompt)
47 return unicode(r, encoding)
3348
34ibid.options = {'base': '.'}49ibid.options = {'base': '.'}
35if exists('ibid.ini'):50if exists('ibid.ini'):
36 ibid.config = FileConfig('ibid.ini')51 ibid.config = FileConfig('ibid.ini')
37 ibid.config.merge(FileConfig('local.ini'))52 ibid.config.merge(FileConfig('local.ini'))
38 sname = None53 sname = None
39
40else:54else:
41 sample_config = resource_stream('ibid', 'config.ini')55 sample_config = resource_filename('ibid', 'config.ini')
42 ibid.config = FileConfig(sample_config)56 ibid.config = FileConfig(sample_config)
4357
44 botname = raw_input(u'What would you like to call your bot? ')58 botname = prompt(u'\nWhat would you like to call your bot? ')
45 ibid.config['botname'] = botname59 ibid.config['botname'] = botname
4660
47 print u'Please enter the full URL of the database to use, or just press Enter for an SQLite database.'61print u'Loading plugins...'
48 ibid.config.databases['ibid'] = raw_input(u'Database URL: ') or 'sqlite:///ibid.db'62for module in getModule('ibid.plugins').iterModules():
4963 try:
50 print u"Please enter the details for the primary source. Press Enter for the default option."64 __import__(module.name)
65 except Exception, e:
66 if options.verbose:
67 print >> stderr, u"Couldn't load %s plugin: %s" % (
68 module.name.replace('ibid.plugins.', ''), unicode(e))
69
70if not exists('ibid.ini'):
71 print u"""
72Database configuration:
73If you want to use the default SQLite database, just press Enter.
74Otherwise please enter a SQLAlchemy database URL.
75Supported databases:
76* mysql://user:pass@host/database
77* postgres://user:pass@host/database (load the CITEXT contrib module first)
78* sqlite:///filename"""
79 ibid.config.databases['ibid'] = prompt(
80 u'Database URL [Default: sqlite:///ibid.db]: '
81 ) or 'sqlite:///ibid.db'
82
83 print u"""
84Source configuration:
85Your bot needs to connect to an IM service (in Ibid terminology, a source) like
86an IRC server or jabber account. Please enter the details for the primary
87source.
88Note: This setup script currently only supports IRC and jabber. You can set up
89other sources manually in ibid.ini.
90
91The source name should be the IRC network name or a generic description for the
92source like 'jabber'.
93"""
51 source = {'nick': '$botname'}94 source = {'nick': '$botname'}
52 sname = raw_input(u'Source name (e.g. freenode, atrum, jabber): ')95 sname = prompt(u'Source name (e.g. freenode, jabber): ')
53 source['server'] = raw_input(u'Server: ')96 source['type'] = prompt(u'Source type (irc, jabber) [Default: irc]: ')
54 port = raw_input(u'Port: ')
55 if port:
56 source['port'] = port
57 source['type'] = raw_input(u'Source type (irc or jabber): ')
5897
59 if source['type'].lower() == 'irc':98 if source['type'].lower() in (u'irc', u''):
60 source['channels'] = [c.strip() for c in raw_input(u'Default channels to join (comma separated): ').split(',')]99 source['server'] = prompt(u'IRC Server: ')
100 port = prompt(u'Port [Default: 6667]: ')
101 if port:
102 source['port'] = port
103 source['channels'] = [c.strip() for c in prompt(
104 u'Channels to join (comma separated) [Default: none]: '
105 ).split(u',')]
61 source['auth'] = ['hostmask', 'nickserv']106 source['auth'] = ['hostmask', 'nickserv']
62 elif source['type'].lower() == 'jabber':107 elif source['type'].lower() == u'jabber':
63 source['jid'] = raw_input(u'JID: ')108 source['jid'] = prompt(u'JID (Jabber address): ')
64 source['password'] = getpass(u'Password: ')109 source['password'] = prompt(u'Password: ', secret=True)
65 source['rooms'] = [r.strip() for r in raw_input(u'Default rooms to join (comma separated): ').split(',')]110 source['rooms'] = [r.strip() for r in prompt(
111 u'MUC rooms to join (comma separated) [Default: none]: '
112 ).split(u',')]
66 source['auth'] = ['implicit']113 source['auth'] = ['implicit']
67 source['ssl'] = raw_input(u'SSL (Y/N): ').lower() in ('y', 'yes', 'true')
68 else:114 else:
69 print 'Invalid source type'115 print u'Invalid source type.'
70 exit(1)116 exit(1)
71117
72 ibid.config.sources[sname] = source118 ibid.config.sources[sname] = source
73119
74 ibid.config.write(open('ibid.ini', 'w'))120 ibid.config.write(open('ibid.ini', 'w'))
75 if not exists('logging.ini'):121 if not exists('logging.ini'):
76 copyfileobj(resource_stream('ibid', 'logging.ini'), open('logging.ini', 'w'))122 copyfileobj(resource_stream('ibid', 'logging.ini'),
123 open('logging.ini', 'w'))
77124
78db = DatabaseManager(check_schema_versions=False)125db = DatabaseManager(check_schema_versions=False)
79Session = db['ibid']126Session = db['ibid']
80upgrade_schemas(Session)127upgrade_schemas(Session)
81128
82print u'Database tables created'129print u"""Database tables created
83130
84print u'Please enter the details for your account. This account will be given full admin permissions.'131Now we need to create an account for you in the bot so it knows who its
85identity = unicode(raw_input('Nick/JID: '))132master is. This account will be given full admin permissions.
86source = sname or unicode(raw_input('Source name: '))133Please enter the details for your account."""
87pass1 = getpass('Password: ')134identity = prompt(u'Your IRC Nick/Jabber ID: ')
88pass2 = getpass('Confirm password: ')135if not identity:
136 print u'Skipping account creation'
137 exit(0)
138source = sname or prompt(u'Source name: ')
139pass1 = prompt(u'Password to identify yourself to the bot: ', secret=True)
140pass2 = prompt(u'Confirm password: ', secret=True)
89141
90if pass1 != pass2:142if pass1 != pass2:
91 print 'Password do not match'143 print u'Password do not match'
92 exit(1)144 exit(1)
93145
94session = Session()146session = Session()
@@ -97,7 +149,8 @@
97account.identities.append(identity)149account.identities.append(identity)
98150
99for permission in (u'accounts', u'sources', u'plugins', u'core', u'admin',151for permission in (u'accounts', u'sources', u'plugins', u'core', u'admin',
100 u'config', u'saydo', u'factoidadmin', u'karmaadmin', u'eval'):152 u'config', u'saydo', u'factoidadmin', u'karmaadmin', u'eval',
153 u'chairmeeting'):
101 perm = Permission(permission, u'auth')154 perm = Permission(permission, u'auth')
102 account.permissions.append(perm)155 account.permissions.append(perm)
103156
@@ -109,6 +162,6 @@
109session.commit()162session.commit()
110session.close()163session.close()
111164
112print 'Account created with admin permissions'165print u'Account created with admin permissions'
113166
114# vi: set et sta sw=4 ts=4:167# vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches