1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
from twisted.news import news, database
6
from twisted.application import strports
7
from twisted.python import usage, log
9
class DBOptions(usage.Options):
11
['module', None, 'pyPgSQL.PgSQL', "DB-API 2.0 module to use"],
12
['dbhost', None, 'localhost', "Host where database manager is listening"],
13
['dbuser', None, 'news', "Username with which to connect to database"],
14
['database', None, 'news', "Database name to use"],
15
['schema', None, 'schema.sql', "File to which to write SQL schema initialisation"],
18
["groups", "g", "groups.list", "File containing group list"],
19
["servers", "s", "servers.list", "File containing server list"]
22
def postOptions(self):
24
self['groups'] = [g.strip() for g in open(self['groups']).readlines() if not g.startswith('#')]
25
self['servers'] = [s.strip() for s in open(self['servers']).readlines() if not s.startswith('#')]
28
__import__(self['module'])
30
log.msg("Warning: Cannot import %s" % (self['module'],))
32
open(self['schema'], 'w').write(
33
database.NewsStorageAugmentation.schema + '\n' +
34
database.makeGroupSQL(self['groups']) + '\n' +
35
database.makeOverviewSQL()
39
'host': self['dbhost'], 'user': self['dbuser'],
40
'database': self['database'], 'dbapiName': self['module']
42
self.db = database.NewsStorageAugmentation(info)
45
class PickleOptions(usage.Options):
47
['file', None, 'news.pickle', "File to which to save pickle"],
50
["groups", "g", "groups.list", "File containing group list"],
51
["servers", "s", "servers.list", "File containing server list"],
52
["moderators", "m", "moderators.list",
53
"File containing moderators list"],
58
def postOptions(self):
60
filename = self['file']
61
self['groups'] = [g.strip() for g in open(self['groups']).readlines()
62
if not g.startswith('#')]
63
self['servers'] = [s.strip() for s in open(self['servers']).readlines()
64
if not s.startswith('#')]
65
self['moderators'] = [s.split()
66
for s in open(self['moderators']).readlines()
67
if not s.startswith('#')]
68
self.db = database.PickleStorage(filename, self['groups'],
72
class Options(usage.Options):
73
synopsis = "Usage: mktap news [options]"
80
["port", "p", "119", "Listen port"],
81
["interface", "i", "", "Interface to which to bind"],
82
["datadir", "d", "news.db", "Root data storage path"],
83
["mailhost", "m", "localhost", "Host of SMTP server to use"]
85
zsh_actions = {"datadir" : "_dirs", "mailhost" : "_hosts"}
88
usage.Options.__init__(self)
91
self.subscriptions = []
94
def opt_group(self, group):
95
"""The name of a newsgroup to carry."""
96
self.groups.append([group, None])
99
def opt_moderator(self, moderator):
100
"""The email of the moderator for the most recently passed group."""
101
self.groups[-1][1] = moderator
104
def opt_subscription(self, group):
105
"""A newsgroup to list as a recommended subscription."""
106
self.subscriptions.append(group)
109
def opt_server(self, server):
110
"""The address of a Usenet server to pass messages to and receive messages from."""
111
self.servers.append(server)
114
def makeService(config):
115
if not len(config.groups):
116
raise usage.UsageError("No newsgroups specified")
118
db = database.NewsShelf(config['mailhost'], config['datadir'])
119
for (g, m) in config.groups:
122
db.addModerator(g, m)
125
for s in config.subscriptions:
127
db.addSubscription(s)
129
if config['interface']:
131
s += ':interface='+config['interface']
132
return strports.service(s, news.UsenetServerFactory(db, config.servers))