Hi,
i have a problem, the source of which is probably the fact, that i have
not understood how to declare global variables - I use the Jython
compiler, but i think this is a Python issue...
First of all, i don not use any classes in this module. The problem is,
that i declare and instantiate some vars outside the functions (global
ones), but when i use them inside the functions, i get an
"UnboundLocalEr ror" error.
Here's the interesting part of the code:
=============== =============== =============== =============== =============== ===============
#imports
....
#CONSTANTS
......
....
#connection to DB
dbcursor_=db.cu rsor()
#GLOBAL VARS
entryList_={}
cmterID_=0 //VARIABLE DECLARATION
projID_=0
fileIDNumber_=0
Commiter_={}
Commit_={}
Project_={}
ProjectVersion_ ={}
def updateCommiterT able(Commiter):
query="INSERT INTO Commiter (pk_cmterID,cmt erName) VALUES
("+str(Commi ter[0])+",\""+str(Com miter[1])+"\");"
dbcursor_.execu te(query)
def updateCommitTab le(Commit):
query="INSERT INTO Commit
(pk_cmitID,cmit Time,fk_cmterID ,cmitProperties ,cmitComment,cm itCommentLines, fk_projID)
VALUES (" \
+str(Commit[0])+",\""+str(Com mit[1])+"\","+str(Com mit[2])+",\""+str(Com mit[3])+"\",\""+str(C ommit[4])+"\","+str(Com mit[5])+","+str(Commi t[6])+");"
dbcursor_.execu te(query)
def updateProjectTa ble(Project):
dbcursor_.execu te("INSERT INTO Project
(pk_projID,proj Name,projWebsit e,projContactPo int,projSrcPath ,projMailPath)
VALUES (" \
+str(Project[0])+",\""+str(Pro ject[1])+"\",\""+str(P roject[2])+"\",\""+str(P roject[3])+"\",\""+str(P roject[4])+"\",\""+str(P roject[5])+"\");")
def updateProjectVe rsionTable(Proj ectVersion):
dbcursor_.execu te("INSERT INTO ProjectVersion
(pfk_projID,pro jName,projVersi on) VALUES (" \
+str(ProjectVer sion[0])+",\""+str(Pro jectVersion[1])+"\",\""+str(P rojectVersion[2])+"\");");
def getLogsLoop():
while
svnLogging_.get CurrentRevision Number()!=svnLo gging_.getLates tRevisionNumber ():
try:
entryList_=svnL ogging_.getNext Logs(PIVOT);
except HeadRevisionRea chedException:
print "Attempting to go over the HEAD revision..."
for entry in entryList_:
print "processing new SVN entry..."
processLogEntry (entry)
entryList_.clea r()
def processLogEntry (entry):
revision = int(entry.getRe vision())
commiter = str(entry.getAu thor())
datetime = getTimeStamp(en try.getDate())
message = str(entry.getMe ssage())
Commiter_[0] = cmterID_ //HERE's THE PROBLEM
Commiter_[1] = commiter
updateCommiterT able(Commiter_)
Commit_[0] = revision
Commit_[1] = datetime
Commit_[2] = cmterID_
Commit_[3] = "" #properties
Commit_[4] = message
Commit_[5] = getNumberOfLine s(message)
Commit_[6] = projID_
updateCommitTab le(Commit_)
ProjectVersion_[0]=projID_
ProjectVersion_[1]=""
ProjectVersion_[2]=""
updateProjectVe rsionTable(Proj ectVersion_)
Project_[0]=projID_
Project_[1]=""
Project_[2]=""
Project_[3]=""
Project_[4]=""
Project_[5]=""
updateProjectTa ble(Project_)
cmterID_+=1
projID_+1
############### ############### HELPER##METHODS ############### ############### #
....
############### ############### HELPER##METHODS ############### ############### #
getLogsLoop()
=============== =============== =============== =============== =============== ===============
And I get:
=============== =============== =============== =============== =============== ===============
Traceback (innermost last):
File "ParseSVN2DB.py ", line 182, in ?
File "ParseSVN2DB.py ", line 87, in getLogsLoop
File "ParseSVN2DB.py ", line 100, in processLogEntry
UnboundLocalErr or: local: 'cmterID_'
=============== =============== =============== =============== =============== ===============
The things is, that cmterID_ HAS BEEN instantiated... I don't understand.
Can somebody please explain?
i have a problem, the source of which is probably the fact, that i have
not understood how to declare global variables - I use the Jython
compiler, but i think this is a Python issue...
First of all, i don not use any classes in this module. The problem is,
that i declare and instantiate some vars outside the functions (global
ones), but when i use them inside the functions, i get an
"UnboundLocalEr ror" error.
Here's the interesting part of the code:
=============== =============== =============== =============== =============== ===============
#imports
....
#CONSTANTS
......
....
#connection to DB
dbcursor_=db.cu rsor()
#GLOBAL VARS
entryList_={}
cmterID_=0 //VARIABLE DECLARATION
projID_=0
fileIDNumber_=0
Commiter_={}
Commit_={}
Project_={}
ProjectVersion_ ={}
def updateCommiterT able(Commiter):
query="INSERT INTO Commiter (pk_cmterID,cmt erName) VALUES
("+str(Commi ter[0])+",\""+str(Com miter[1])+"\");"
dbcursor_.execu te(query)
def updateCommitTab le(Commit):
query="INSERT INTO Commit
(pk_cmitID,cmit Time,fk_cmterID ,cmitProperties ,cmitComment,cm itCommentLines, fk_projID)
VALUES (" \
+str(Commit[0])+",\""+str(Com mit[1])+"\","+str(Com mit[2])+",\""+str(Com mit[3])+"\",\""+str(C ommit[4])+"\","+str(Com mit[5])+","+str(Commi t[6])+");"
dbcursor_.execu te(query)
def updateProjectTa ble(Project):
dbcursor_.execu te("INSERT INTO Project
(pk_projID,proj Name,projWebsit e,projContactPo int,projSrcPath ,projMailPath)
VALUES (" \
+str(Project[0])+",\""+str(Pro ject[1])+"\",\""+str(P roject[2])+"\",\""+str(P roject[3])+"\",\""+str(P roject[4])+"\",\""+str(P roject[5])+"\");")
def updateProjectVe rsionTable(Proj ectVersion):
dbcursor_.execu te("INSERT INTO ProjectVersion
(pfk_projID,pro jName,projVersi on) VALUES (" \
+str(ProjectVer sion[0])+",\""+str(Pro jectVersion[1])+"\",\""+str(P rojectVersion[2])+"\");");
def getLogsLoop():
while
svnLogging_.get CurrentRevision Number()!=svnLo gging_.getLates tRevisionNumber ():
try:
entryList_=svnL ogging_.getNext Logs(PIVOT);
except HeadRevisionRea chedException:
print "Attempting to go over the HEAD revision..."
for entry in entryList_:
print "processing new SVN entry..."
processLogEntry (entry)
entryList_.clea r()
def processLogEntry (entry):
revision = int(entry.getRe vision())
commiter = str(entry.getAu thor())
datetime = getTimeStamp(en try.getDate())
message = str(entry.getMe ssage())
Commiter_[0] = cmterID_ //HERE's THE PROBLEM
Commiter_[1] = commiter
updateCommiterT able(Commiter_)
Commit_[0] = revision
Commit_[1] = datetime
Commit_[2] = cmterID_
Commit_[3] = "" #properties
Commit_[4] = message
Commit_[5] = getNumberOfLine s(message)
Commit_[6] = projID_
updateCommitTab le(Commit_)
ProjectVersion_[0]=projID_
ProjectVersion_[1]=""
ProjectVersion_[2]=""
updateProjectVe rsionTable(Proj ectVersion_)
Project_[0]=projID_
Project_[1]=""
Project_[2]=""
Project_[3]=""
Project_[4]=""
Project_[5]=""
updateProjectTa ble(Project_)
cmterID_+=1
projID_+1
############### ############### HELPER##METHODS ############### ############### #
....
############### ############### HELPER##METHODS ############### ############### #
getLogsLoop()
=============== =============== =============== =============== =============== ===============
And I get:
=============== =============== =============== =============== =============== ===============
Traceback (innermost last):
File "ParseSVN2DB.py ", line 182, in ?
File "ParseSVN2DB.py ", line 87, in getLogsLoop
File "ParseSVN2DB.py ", line 100, in processLogEntry
UnboundLocalErr or: local: 'cmterID_'
=============== =============== =============== =============== =============== ===============
The things is, that cmterID_ HAS BEEN instantiated... I don't understand.
Can somebody please explain?
Comment