python IndentationError: expected an indented block [closed]

2024/11/9 3:50:41

I am trying to fix this script. I keep receiving an error

11:14:22 # ./datasource_config.pyFile "./datasource_config.py", line 11global AdminConfig^IndentationError: expected an indented block

I've tried with my editor to change the tabs to spaces and use 4 spaces and vice versa but it seems like no matter what I try I still keep running into this error. Any ideas?

#!/usr/bin/python
import sys,java
from java.util import Properties
from java.io import FileInputStream
from org.python.modules import time
lineSep = java.lang.System.getProperty('line.separator')def datasource(cluster,user,password,url,env,jdbc_driver,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout):#Declare global variables 
global    AdminConfig 
global    AdminControl## JDBCProvider ##name = "jdbcOracle"+ envprint " Name of JDBC Provider which will be created ---> " + nameprint " ----------------------------------------------------------------------------------------- "# Gets the name of cellcell = AdminControl.getCell()cellid = AdminConfig.getid('/Cell:'+ cell +'/')print " ----------------------------------------------------------------------------------------- "# checking for the existence of ClusterServerid = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/')print " Checking for existence of Server :" + clusterif len(Serverid) == 0:print "Cluster doesnot exists "else:print "Cluster exist:"+ clusterprint " ----------------------------------------------------------------------------------------- "## removing old jdbc provider and creating a new jdbc provider print " Checking for the existence of JDBC Provider :"+ name s2 = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/JDBCProvider:'+ name) if len(s2) > 0:print " JDBC Provider exists with name :"+ nameprint " Removing JDBC Provider with name :"+ nameAdminConfig.remove(s2)print " JDBC Provider removed "AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- " ## Creating New JDBC Provider ##print " Creating New JDBC Provider :"+ name n1 = ["name" , name ]desc = ["description" , "Oracle JDBC Driver"]impn = ["implementationClassName" , "oracle.jdbc.pool.OracleConnectionPoolDataSource"]classpath = ["classpath" , jdbc_driver ]attrs1 = [n1 , impn , desc , classpath]jdbc = AdminConfig.create('JDBCProvider' , Serverid , attrs1)print " New JDBC Provider created :"+ name AdminConfig.save()print " Saving Configuraion " print " ----------------------------------------------------------------------------------------- "## checking for the existence of JAASAuthData and deleting ## node = AdminControl.getNode()alias1 = node +"/"+ envprint " Checking for the existence of JAASAUTHDATA :"+ alias1 jaasAuthDataList = AdminConfig.list("JAASAuthData")if len(jaasAuthDataList) == 0: print " Creating New JAASAuthData with Alias name :"+ alias1sec = AdminConfig.getid('/Cell:'+ cell +'/Security:/')alias_attr = ["alias" , alias1]desc_attr = ["description" , "alias"]userid_attr = ["userId" , user ]password_attr = ["password" , password]attrs = [alias_attr , desc_attr , userid_attr , password_attr ]authdata = AdminConfig.create('JAASAuthData' , sec , attrs)print " Created new JASSAuthData with Alias name :"+ alias1AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- "else :matchFound = 0 jaasAuthDataList = AdminConfig.list("JAASAuthData") jaasAuthDataList=jaasAuthDataList.split(lineSeparator)for jaasAuthId in jaasAuthDataList:getAlias = AdminConfig.showAttribute(jaasAuthId, "alias")if (cmp(getAlias,alias1) == 0):print " JAASAuthData exists with name :"+ alias1print " Removing JAASAuthData with name :"+ alias1AdminConfig.remove(jaasAuthId)print " JAASAuthData removed " AdminConfig.save()print " Saving Configuraion " matchFound = 1breakif (matchFound == 0):print " No match was found for the given JASSAuthData : "+ alias1#endIfprint " ----------------------------------------------------------------------------------------- "## J2C Authentication Entries ##print " Creating New JAASAuthData with Alias name :"+ alias1sec = AdminConfig.getid('/Cell:'+ cell +'/Security:/')alias_attr = ["alias" , alias1]desc_attr = ["description" , "alias"]userid_attr = ["userId" , user ]password_attr = ["password" , password]attrs = [alias_attr , desc_attr , userid_attr , password_attr ]authdata = AdminConfig.create('JAASAuthData' , sec , attrs)print " Created new JASSAuthData with Alias name :"+ alias1 AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- " ## DataSource ##datasource = "DataSource"+ envprint " Name of datasource which will be created on JDBC Provider :"+ name +" is :"+ datasourceds = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/JDBCProvider:'+ name) name1 = ["name" , datasource]jndi = ["jndiName" , "jdbc/tiers3DS"]authentication = ["authDataAlias" , alias1]st_cachesize = ["statementCacheSize" , "150"]ds_hlpclass = ["datasourceHelperClassname" , "com.ibm.websphere.rsadapter.Oracle10gDataStoreHelper"]map_configalias_attr=["mappingConfigAlias", "DefaultPrincipalMapping"]map_attrs=[authentication , map_configalias_attr]mapping_attr=["mapping", map_attrs]ds_attr = [name1 , jndi , authentication , st_cachesize , ds_hlpclass ,mapping_attr ]newds = AdminConfig.create('DataSource' , ds , ds_attr)print " New DataSource created with name :"+ datasource AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- "## set the properties for the datasource ##print " Setting the properties for DataSource :"+ datasourcenewds1 = AdminConfig.getid('/Cell:'+ cell +'/ServerCluster:'+ cluster +'/JDBCProvider:'+ name +'/DataSource:'+ datasource)propSet = AdminConfig.create('J2EEResourcePropertySet' , newds1 , "")name3 = ["name" , "URL"]type = ["type" , "java.lang.String"]required = ["required" , "true"]value = ["value" , url]rpAttrs = [name3 , type , required , value]jrp = AdminConfig.create('J2EEResourceProperty' , propSet , rpAttrs)print " Properties created for DataSource :"+ datasource AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- "# Create an associated connection pool for the new DataSource#print " Creating Connection Pool Setting for DataSource :"+ datasourcetimeout = ["connectionTimeout" , timeOut]maxconn = ["maxConnections" , maxConn]minconn = ["minConnections" , minConn]reaptime = ["reapTime" , reapTime]unusedtimeout = ["unusedTimeout" , unusdTimeout]agedtimeout = ["agedTimeout" , agedTimeout]purgepolicy = ["purgePolicy" , "EntirePool"]connPoolAttrs = [timeout , maxconn , minconn , reaptime , unusedtimeout , agedtimeout , purgepolicy] AdminConfig.create("ConnectionPool", newds , connPoolAttrs)print " Connection Pool Setting created for DataSource :"+ datasource AdminConfig.save()print " Saving Configuraion "print " ----------------------------------------------------------------------------------------- "## Full Syncronization ##print " Syncronizing configuration with Master Repository "nodelist = AdminTask.listManagedNodes().split(lineSep)for nodename in nodelist :print " Doing Full Resyncronization of node.......... "####################Identifying the ConfigRepository MBean and assign it to variable######################repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')print AdminControl.invoke(repo, 'refreshRepositoryEpoch')sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')print AdminControl.invoke(sync , 'sync')#time.sleep(20)print " ----------------------------------------------------------------------------------------- "print " Full Resyncronization completed "print " ----------------------------------------------------------------------------------------- "#######Restarting Node Agent#########nodelist = AdminTask.listManagedNodes().split(lineSep)for nodename in nodelist :print " Restarting Nodeagent of "+nodename+" node " na = AdminControl.queryNames('type=NodeAgent,node='+nodename+',*') AdminControl.invoke(na,'restart','true true') print " ----------------------------------------------------------------------------------------- "time.sleep(30)##########Testing Database Connection################dsid = AdminConfig.getid('/ServerCluster:'+ cluster +'/JDBCProvider:'+ name +'/DataSource:'+ datasource +'/')print " Testing Database Connection"print AdminControl.testConnection(dsid)print " ----------------------------------------------------------------------------------------- "
####################################################################################################################
#####################################################################################################################main program starts herearglen=len(sys.argv)num_exp_args=2if (arglen != num_exp_args):print "Two arguments are required.one of them is property file"print " ----------------------------------------------------------------------------------------- "sys.exit(-1)propFile=sys.argv[0]properties=Properties();try:properties.load(FileInputStream(propFile))print " ----------------------------------------------------------------------------------------- "print "Succesfully read property file "+propFileprint " ----------------------------------------------------------------------------------------- "except:print "Cannot read property file "+propFile
sys.exit(-1)print " ----------------------------------------------------------------------------------------- "cluster = str(properties.getProperty("CLUSTER_NAME"))
env = sys.argv[1]
user = str(properties.getProperty("dbms.userId"))
password = str(properties.getProperty("dbms.password"))
url = str(properties.getProperty("dbms.url"))
jdbc_driver = str(properties.getProperty("JDBC_DRIVER_PATH"))
timeOut = int(properties.getProperty("TIMEOUT"))
maxConn = int(properties.getProperty("MAXCONN"))
minConn = int(properties.getProperty("MINCONN"))
reapTime = int(properties.getProperty("REAPTIME"))
unusdTimeout = int(properties.getProperty("UNUSEDTIMEOUT"))
agedTimeout = int(properties.getProperty("AGEDTIMEOUT"))datasource(cluster,user,password,url,env,jdbc_driver,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout)
Answer

You have no indentation in your Python code!

def datasource(cluster,user,password,url,env,jdbc_driver,timeOut,maxConn,minConn,reapTime,unusdTimeout,agedTimeout):#Declare global variables global    AdminConfig global    AdminControl

Fixing this, there will be others. The next one to fix is:

if len(Serverid) == 0:print "Cluster doesnot exists "    
else:    print "Cluster exist:"+ cluster

and so on.

https://en.xdnf.cn/q/120535.html

Related Q&A

how to tell an infinite loop to end once one number repeats twice in a row (in python 3.4)

The title says it all. I have an infinite loop of randomly generated numbers from one to six that I need to end when 6 occurs twice in a row.

Is it possible to customize the random function to avoid too much repetition of words? [duplicate]

This question already exists:Customizing the random function without using append, or list, or other container?Closed last year.Theoretically, when randomization is used, the same word may be printed …

country convert to continent

def country_to_continent(country_name):country_alpha2 = pc.country_name_to_country_alpha2(country_name)country_continent_code = pc.country_alpha2_to_continent_code(country_alpha2)country_continent_name…

Iterate through a list and delete certain elements

Im working on an assignment in my computer class, and Im having a hard time with one section of the code. I will post the assignment guidelines (the bolded part is the code Im having issues with):You a…

How to count numbers in a list via certain rules?

Just to say I have a str and a list of strs and I want to count how many strs in the list that is contained in a str. Is there an elegant way to do that?For example, l = {"foo", "bar&qu…

Count character occurrences in a Python string

I want to get the each character count in a given sentence. I tried the below code and I got the count of every character but it displays the repeated characters count in the output. How to delete repe…

The Concept Behind itertoolss product Function

so basically i want to understand the concept of product() function in itertools. i mean what is the different between yield and return. And can this code be shorten down anyway.def product1(*args, **k…

how to read data from multiple sheets in a single csv file using python [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.Questions asking for code must demonstrate a minimal understanding of the problem being solved. Incl…

Quality Center: Set a Step Field in Python

I have a very simple problem here. I want to achieve the following VB script Code in Python:- dim objSfact dim objOrun dim mystep Set objOrun = QCutil.CurrentRun Set objSfact = objOrun.StepFactory…

Convert for loop from Python to C++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…