- new listclients script
- distutils setup script - moved scripts to bin subdirectory git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@216 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
a0778661c6
commit
5b7a1d990d
3 changed files with 67 additions and 1 deletions
123
bin/createclient
Executable file
123
bin/createclient
Executable file
|
@ -0,0 +1,123 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright (C) 2007 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$
|
||||
|
||||
import getopt, sys, sqlalchemy
|
||||
|
||||
from gnuviechadmin import client, exceptions
|
||||
|
||||
def usage():
|
||||
print """Usage: %s [-h|--help] [-v|--verbose]
|
||||
[-t <title>|--title=<title>]
|
||||
-f <firstname>|--firstname=<firstname> -l <lastname>|--lastname=<lastname>
|
||||
-a <address1>|--address=<address1> [--address2=<address2>]
|
||||
-z <zip>|--zip=<zip> -c <city>|--city=<city> [--country=<isocode>]
|
||||
[-o <organisation>|--organisation=<organisation>]
|
||||
-e <email>|--email=<email> -p <phone>|--phone=<phone>
|
||||
[-m <mobile>|--mobile=<mobile>] [-x <fax>|--fax=<fax>]
|
||||
|
||||
General options:
|
||||
-h, --help show this usage message and exit
|
||||
-v, --verbose verbose operation
|
||||
|
||||
Mandatory client data options:
|
||||
-f, --firstname firstname
|
||||
-l, --lastname lastname
|
||||
-a, --address street address
|
||||
-z, --zip zip or postal code
|
||||
-c, --city city or location
|
||||
-e, --email contact email address
|
||||
-p, --phone telephone number
|
||||
|
||||
Optional client data options:
|
||||
--address2 optional second line of the street address
|
||||
-o, --organisation option organisation
|
||||
--country country (defaults to de)
|
||||
-t, --title optional title
|
||||
-m, --mobile optional mobile number
|
||||
-x, --fax optional fax number
|
||||
""" % (sys.argv[0])
|
||||
|
||||
def main():
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv[1:],
|
||||
"hvf:l:a:z:c:e:p:o:t:m:x:",
|
||||
["help", "verbose", "firstname=",
|
||||
"lastname=", "address=", "zip=",
|
||||
"city=", "email=", "phone=",
|
||||
"address2=", "organisation=",
|
||||
"country=", "title=", "mobile=",
|
||||
"fax="])
|
||||
except getopt.GetoptError:
|
||||
usage()
|
||||
sys.exit(2)
|
||||
clientdata = {}
|
||||
verbose = False
|
||||
for o, a in opts:
|
||||
if o in ("-v", "--verbose"):
|
||||
verbose = True
|
||||
if o in ("-h", "--help"):
|
||||
usage()
|
||||
sys.exit()
|
||||
if o in ("-f", "--firstname"):
|
||||
clientdata["firstname"] = a
|
||||
if o in ("-l", "--lastname"):
|
||||
clientdata["lastname"] = a
|
||||
if o in ("-a", "--address"):
|
||||
clientdata["address1"] = a
|
||||
if o in ("-z", "--zip"):
|
||||
clientdata["zip"] = a
|
||||
if o in ("-c", "--city"):
|
||||
clientdata["city"] = a
|
||||
if o == "--country":
|
||||
clientdata["country"] = a
|
||||
if o in ("-t", "--title"):
|
||||
clientdata["title"] = a
|
||||
if o in ("-m", "--mobile"):
|
||||
clientdata["mobile"] = a
|
||||
if o in ("-e", "--email"):
|
||||
clientdata["email"] = a
|
||||
if o in ("-o", "--organisation"):
|
||||
clientdata["organisation"] = a
|
||||
if o in ("-x", "--fax"):
|
||||
clientdata["fax"] = a
|
||||
if o in ("-p", "--phone"):
|
||||
clientdata["phone"] = a
|
||||
if verbose:
|
||||
print "parsed client data is ", clientdata
|
||||
try:
|
||||
myclient = client.Client(**clientdata)
|
||||
except exceptions.MissingFieldsError, mfe:
|
||||
print mfe
|
||||
usage()
|
||||
sys.exit(2)
|
||||
try:
|
||||
sess = sqlalchemy.create_session()
|
||||
sess.save(myclient)
|
||||
sess.flush()
|
||||
except sqlalchemy.exceptions.SQLError, e:
|
||||
print "saving client failed: ", e
|
||||
sys.exit(2)
|
||||
if verbose:
|
||||
print myclient
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
33
bin/listclients
Executable file
33
bin/listclients
Executable file
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
#
|
||||
# Copyright (C) 2007 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.
|
||||
|
||||
import sqlalchemy
|
||||
|
||||
from gnuviechadmin import client, exceptions
|
||||
|
||||
def main():
|
||||
session = sqlalchemy.create_session()
|
||||
query = session.query(client.Client)
|
||||
|
||||
for row in query.select():
|
||||
print row
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue