1
0
Fork 0

Code style changes

* make code PEP8 clean (addresses #18)
 * add copyright information to all python files


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/trunk@257 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2008-06-06 19:20:18 +00:00
parent 7c4d25da43
commit 09180938f1
45 changed files with 759 additions and 514 deletions

View file

@ -1,74 +1,93 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007 Jan Dittberner
# $Id$
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
import getopt, sys
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
import getopt
import sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --firstname=<firstname> --lastname=<lastname> \
--address1=<address1> --town=<town> --zipcode=<zipcode> \
[--address2=<address2>] [--country=<country>] [--state=<state>] \
[--active=true|false] [--phone=<phone>] [--mobile=<mobile>]
- adds a new client
""" % {'process': sys.argv[0]}
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --firstname=<firstname> --lastname=<lastname> \
--address1=<address1> --town=<town> --zipcode=<zipcode> \
[--address2=<address2>] [--country=<country>] [--state=<state>] \
[--active=true|false] [--phone=<phone>] [--mobile=<mobile>]
- adds a new client
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help',
'firstname=', 'lastname=', 'address1=',
'town=', 'zipcode=', 'address2=',
'country=', 'state=', 'active=',
'phone=', 'mobile='])
except getopt.GetoptError:
usage()
sys.exit(1)
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help',
'firstname=', 'lastname=',
'address1=',
'town=', 'zipcode=', 'address2=',
'country=', 'state=', 'active=',
'phone=', 'mobile='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
dict(options).has_key('-h') or
dict(options).has_key('--help') or
not dict(options).has_key('--firstname') or
not dict(options).has_key('--lastname') or
not dict(options).has_key('--address1') or
not dict(options).has_key('--town') or
not dict(options).has_key('--zipcode') or
not dict(options)['--firstname'].strip() or
not dict(options)['--lastname'].strip() or
not dict(options)['--address1'].strip() or
not dict(options)['--town'].strip() or
not dict(options)['--zipcode'].strip()):
usage()
sys.exit(1)
if (not options or
'-h' in dict(options) or
'--help' in dict(options) or
not '--firstname' in dict(options) or
not '--lastname' in dict(options) or
not '--address1' in dict(options) or
not '--town' in dict(options) or
not '--zipcode' in dict(options) or
not dict(options)['--firstname'].strip() or
not dict(options)['--lastname'].strip() or
not dict(options)['--address1'].strip() or
not dict(options)['--town'].strip() or
not dict(options)['--zipcode'].strip()):
usage()
sys.exit(1)
po = dict(options)
for key in po.keys():
po[key] = po[key].strip()
client = Client()
client.firstname = po['--firstname']
client.lastname = po['--lastname']
client.address1 = po['--address1']
client.town = po['--town']
client.zipcode = po['--zipcode']
if po.has_key('--active'):
client.active = (po['--active'] == 'true')
else:
client.active = True
if po.has_key('--address2') and po['--address2']:
client.address2 = po['--address2']
if po.has_key('--country') and po['--country']:
client.country = po['--country']
if po.has_key('--state') and po['--state']:
client.state = po['--state']
if po.has_key('--phone') and po['--phone']:
client.phone = po['--phone']
if po.has_key('--mobile') and po['--mobile']:
client.mobile = po['--mobile']
session.save(client)
session.flush()
po = dict(options)
for key in po.keys():
po[key] = po[key].strip()
client = Client()
client.firstname = po['--firstname']
client.lastname = po['--lastname']
client.address1 = po['--address1']
client.town = po['--town']
client.zipcode = po['--zipcode']
if '--active' in po:
client.active = (po['--active'] == 'true')
else:
client.active = True
if '--address2' in po and po['--address2']:
client.address2 = po['--address2']
if '--country' in po and po['--country']:
client.country = po['--country']
if '--state' in po and po['--state']:
client.state = po['--state']
if '--phone' in po and po['--phone']:
client.phone = po['--phone']
if '--mobile' in po and po['--mobile']:
client.mobile = po['--mobile']
session.save(client)
session.flush()

View file

@ -1,59 +1,77 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007 Jan Dittberner
# $Id$
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
import getopt, sys
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
import getopt
import sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --domain=<domain> --sysuser=<sysuser> --type=MASTER|SLAVE \
[[--ns=<nameserver>] [--mx=<mxserver[,prio]>] [--a=<ipaddress>] ...]
- adds a new domain
""" % {'process': sys.argv[0]}
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --domain=<domain> --sysuser=<sysuser> --type=MASTER|SLAVE \
[[--ns=<nameserver>] [--mx=<mxserver[,prio]>] [--a=<ipaddress>] ...]
- adds a new domain
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help',
'domain=', 'sysuser=',
'type=', 'ns=', 'mx=', 'a='])
except getopt.GetoptError:
usage()
sys.exit(1)
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help',
'domain=', 'sysuser=',
'type=', 'ns=', 'mx=', 'a='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
dict(options).has_key('-h') or
dict(options).has_key('--help') or
not dict(options).has_key('--domain') or
not dict(options).has_key('--sysuser') or
not dict(options)['--sysuser'].strip() or
not dict(options)['--domain'].strip()):
usage()
sys.exit(1)
if (not options or
'-h' in dict(options) or
'--help' in dict(options) or
not '--domain' in dict(options) or
not '--sysuser' in dict(options) or
not dict(options)['--sysuser'].strip() or
not dict(options)['--domain'].strip()):
usage()
sys.exit(1)
po = {}
for (key, value) in options:
if po.has_key(key):
po[key].append(value.strip())
else:
po[key] = [value.strip()]
po = {}
for (key, value) in options:
if key in po:
po[key].append(value.strip())
else:
po[key] = [value.strip()]
# fetch the sysuser
query = session.query(SysUser)
sysuser = query.get_by(name = po['--sysuser'][0])
if not sysuser:
print "Invalid system user"
allsysusers = query.get_by(name = '*')
if allsysusers:
print "Valid system users are:\n%s" % ("\n".join(allsysusers))
else:
print "No system users defined yet."
sys.exit(1)
# fetch the sysuser
query = session.query(SysUser)
sysuser = query.get_by(name = po['--sysuser'][0])
if not sysuser:
print "Invalid system user"
allsysusers = query.get_by(name = '*')
if allsysusers:
print "Valid system users are:\n%s" % ("\n".join(allsysusers))
else:
print "No system users defined yet."
sys.exit(1)
print sysuser.domains
print sysuser.domains

View file

@ -1,45 +1,64 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2007 Jan Dittberner
# $Id$
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
import getopt, sys
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
import getopt
import sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --domain=<domain> [--password=<password>]
- adds a new pop user for the given domain
- if the optional password is ommitted a generated one is used
- the password is checked using cracklib
- if the password is too weak a generated one is used
""" % {'process': sys.argv[0]}
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --domain=<domain> [--password=<password>]
- adds a new pop user for the given domain
- if the optional password is ommitted a generated one is used
- the password is checked using cracklib
- if the password is too weak a generated one is used
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h", ['help', 'password=', 'domain='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
dict(options).has_key('-h') or
dict(options).has_key('--help') or
not dict(options).has_key('--domain') or
not dict(options)['--domain'].strip()):
usage()
sys.exit(1)
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help', 'password=', 'domain='])
except getopt.GetoptError:
usage()
sys.exit(1)
# specify the domain
query = session.query(Domain)
domain = query.get_by(name = dict(options)['--domain'].strip())
if not domain:
print "Invalid Domain"
print "valid domains are:\n%s" % ("\n".join(query.get()))
sys.exit(1)
print domain.popaccounts
if (not options or
'-h' in dict(options) or
'--help' in dict(options) or
not '--domain' in dict(options) or
not dict(options)['--domain'].strip()):
usage()
sys.exit(1)
# specify the domain
query = session.query(Domain)
domain = query.get_by(name = dict(options)['--domain'].strip())
if not domain:
print "Invalid Domain"
print "valid domains are:\n%s" % ("\n".join(query.get()))
sys.exit(1)
print domain.popaccounts

View file

@ -1,53 +1,72 @@
#!/usr/bin/env python
#
# Copyright (c) 2007 Jan Dittberner
# $Id$
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
import getopt, sys
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
import getopt
import sys
from gnuviechadmin.dblayer import *
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --type=admin|reseller|client --clientid=<clientid> \
[--name=<name>] [--home=<home>] [--shell=<shell>] [--password] \
[--sysuid=<uid>]
- adds a new system user
""" % {'process': sys.argv[0]}
def usage():
print """Usage information:
=====================
%(process)s -h|--help
- prints this help text
%(process)s --type=admin|reseller|client --clientid=<clientid> \
[--name=<name>] [--home=<home>] [--shell=<shell>] [--password] \
[--sysuid=<uid>]
- adds a new system user
""" % {'process': sys.argv[0]}
if __name__ == "__main__":
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help',
'type=', 'clientid=', 'name=', 'home=',
'shell=', 'password=', 'sysuid='])
except getopt.GetoptError:
usage()
sys.exit(1)
try:
(options, args) = getopt.getopt(sys.argv[1:], "h",
['help', 'type=', 'clientid=',
'name=', 'home=', 'shell=',
'password=', 'sysuid='])
except getopt.GetoptError:
usage()
sys.exit(1)
if (not options or
dict(options).has_key('-h') or
dict(options).has_key('--help') or
not dict(options).has_key('--type') or
not dict(options).has_key('--clientid') or
not dict(options)['--type'].strip() or
not dict(options)['--clientid'].strip() or
not dict(options)['--type'].strip() in ('admin', 'reseller', 'client')):
usage()
sys.exit(1)
if (not options or
'-h' in dict(options) or
'--help' in dict(options) or
not '--type' in dict(options) or
not '--clientid' in dict(options) or
not dict(options)['--type'].strip() or
not dict(options)['--clientid'].strip() or
not dict(options)['--type'].strip() in ('admin', 'reseller',
'client')):
usage()
sys.exit(1)
query = session.query(Client)
client = query.get_by(clientid = dict(options)['--clientid'].strip())
if not client:
print "Invalid client"
query = session.query(Client)
client = query.get_by(clientid = dict(options)['--clientid'].strip())
if not client:
print "Invalid client"
allclients = query.select()
if allclients:
print "Valid clients are:\n- %s" % "\n- ".join([str(client) for client in allclients])
print "Valid clients are:\n- %s" % "\n- ".join(
[str(client) for client in allclients])
else:
print "No clients defined yet."
sys.exit(1)
print client.sysusers
print client.sysusers

View file

@ -6,7 +6,7 @@ meta = BoundMetaData(migrate_engine)
domains = Table('domains', meta, autoload = True)
mailalias = Table(
'mailalias', meta,
Column('mailaliasid', Integer, primary_key = True),
Column('mailaliasid', Integer, primary_key = True),
Column('domainid', Integer, ForeignKey('domains.id'), nullable = False),
Column('email', String(255), nullable = False),
Column('target', TEXT, nullable = False),
@ -24,10 +24,12 @@ mailpassword = Table(
Column('spamcheck', Boolean, default = False),
Column('sajunkscore', Integer))
def upgrade():
mailalias.create()
mailpassword.create()
def downgrade():
mailpassword.drop()
mailalias.drop()

View file

@ -31,10 +31,12 @@ sysuser_table = Table(
Column('md5pass', String(34)),
Column('sysuid', Integer))
def upgrade():
client_table.create()
sysuser_table.create()
def downgrade():
sysuser_table.drop()
client_table.drop()

View file

@ -9,9 +9,11 @@ sysuidrefcol = Column('sysuserid', Integer,
ForeignKey('sysuser.sysuserid'),
nullable = False)
def upgrade():
sysuidrefcol.create(domains)
def downgrade():
col = domains.c.sysuserid
col.drop()

View file

@ -1,4 +1,5 @@
#!/usr/bin/python
from migrate.versioning.shell import main
main(url='postgres://jan:heyyou97@localhost:5432/testdb',repository='gnuviechadmin')
main(url='postgres://jan:heyyou97@localhost:5432/testdb',
repository='gnuviechadmin')

View file

@ -1,3 +1,23 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
from sqlalchemy import *
from entities import *

View file

@ -1,4 +1,27 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007, 2008 by Jan Dittberner.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Version: $Id$
class Client(object):
def __repr__(self):
return "%s(clientid=%s,firstname=%s,lastname=%s)" % \
(self.__class__.__name__,
@ -6,7 +29,9 @@ class Client(object):
self.firstname,
self.lastname)
class PopAccount(object):
def __repr__(self):
return "%s(%s,%d,%d,%d,%s,%s,%s)" % \
(self.__class__.__name__,
@ -18,7 +43,9 @@ class PopAccount(object):
self.cryptpass,
self.clearpass)
class SysUser(object):
def __repr__(self):
return "%s(%d,%s,%d,%s,%s,%s,%d,%d,%s,%d)" % \
(self.__class__.__name__,
@ -33,7 +60,9 @@ class SysUser(object):
self.md5pass,
self.sysuid)
class Domain(object):
def __repr__(self):
return "%s(%d,%s,%s,%s,%s,%s,%s)" % \
(self.__class__.__name__,