# $SnapHashLicense:
#
# SnapLogic - Open source data services
#
# Copyright (C) 2008 - 2009, SnapLogic, Inc. All rights reserved.
#
# See http://www.snaplogic.org for more information about
# the SnapLogic project.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
#
# "SnapLogic" is a trademark of SnapLogic, Inc.
#
#
# $
# $Id: create_table_wizard.py 7781 2009-05-29 01:29:12Z dhiraj $
import sys, getopt, time
from snaplogic import snapi
from snaplogic.snapi_base import keys
from snaplogic.snapi_base.exceptions import SnapiHttpException
def usage():
"""Print usage information about this program."""
print "Usage:"
print " %s [-s <server_url>] [-u username/password]" % sys.argv[0]
print " -s <server_url> Specify the URL of the SnapLogic server to connect to."
print " -u <user/pass> Username and password to use."
def make_credentials(username):
"""Parse username/password argument and construct credentials token."""
if username is None:
return None
userpass = username.split('/')
if len(userpass) != 2:
print "Invalid or missing username/password argument '" + username + "'"
sys.exit(1)
return (userpass[0], userpass[1])
def print_resource_validate_info(error):
"""Print out useful information about resource validation errors and exit."""
print "Resource validation failed with the following error"
# This should be a call to some super snapi helper routine which unpacks errors nicely
print error
sys.exit(1)
# Default values for the required parameters
username = None # Default authorization is anonymous
server = 'http://localhost:8088' # URL of the SnapLogic data server to which we connect
# Processing of command line arguments
try:
opts, args = getopt.getopt(sys.argv[1:], "s:u:h", ["server=", "username=", "help"])
except getopt.GetoptError, e:
print 'Options error:', e
usage()
sys.exit(1)
for o, a in opts:
if o in ("-s", "--server"):
server = a
elif o in ("-u", "--username"):
username = a
elif o in ("-h", "--help"):
usage()
sys.exit()
res_uri = '/db/table_wizard'
# Construct the credentials if any were provided.
creds = make_credentials(username)
try:
resdef = snapi.get_resource_object(server + res_uri, creds)
except SnapiHttpException, e:
if e.status != 404:
raise e
else:
# The resource already exists. Just exit
sys.exit()
dba_resdef = snapi.create_resource_object(server,'snaplogic.components.DBAnalyzer', creds)
dba_resdef.set_property_value('DBConnect', '$?{CONNECT_URI}')
dba_resdef.set_property_value('BaseURI', '$?{BASE_URI}')
dba_resdef.define_param('BASE_URI', None)
dba_resdef.define_param('CONNECT_URI', None)
error = dba_resdef.validate()
if error:
print_resource_validate_info(error)
dba_resdef.save(res_uri)
|