create_table_wizard.py :  » Development » SnapLogic » snaplogic » example » tutorial » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » SnapLogic 
SnapLogic » snaplogic » example » tutorial » create_table_wizard.py
# $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)


        
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.