LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-09-2007, 03:25 PM   #1
kpachopoulos
Member
 
Registered: Feb 2004
Location: Athens, Greece
Distribution: Gentoo,FreeBSD, Debian
Posts: 704

Rep: Reputation: 30
python question


Hi,
i have a problem, the source of which is probably the fact, that i have not understood how to declare global variables.

Here's the interesting part of the code:
Code:
import pdb
from paxosk.sqoss.java.svn import SVNLogging
from paxosk.sqoss.java.svn import HeadRevisionReachedException
from java.util import  List
from org.tmatesoft.svn.core import SVNLogEntry
from DBTablesHandler import DBTablesHandler
from com.ziclix.python.sql import zxJDBC


#################################CONSTANTS############################################
#DB SPECIFIC CONSTANTS
SERVER_HOSTNAME='localhost';
DB_NAME='sqoss';
USER='kostas';
PASSWD='XYZ';
PORT=3306;

#SVN sPECIFIC CONSTANTS
PIVOT=100
SVN_REPOS="file:///home/kostas/sqo-oss/svn/kde" 
#################################CONSTANTS############################################

#DEBUG
#pdb.set_trace()

#################################CONNECTIONS##########################################
##CONNECT TO SVN
svnLogging_=SVNLogging(SVN_REPOS)   
print "Connection established to SVN repository..."  
##
##CONNECT TO DATABASE
params = {}
params['serverName']=SERVER_HOSTNAME
params['databaseName']=DB_NAME
params['user']=USER
params['password']=PASSWD
params['port']=PORT
db = apply(zxJDBC.connectx, ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource",), params)
dbcursor_=db.cursor()
print "Connection established to  database..."     
##       
#################################CONNECTIONS##########################################

entryList_={}
cmterID_=0          //VARIABLE DECLARATION
projID_=0
fileIDNumber_=0
Commiter_={}
Commit_={}
Project_={}        
ProjectVersion_={}
              

def updateCommiterTable(Commiter):
    query="INSERT INTO Commiter (pk_cmterID,cmterName) VALUES ("+str(Commiter[0])+",\""+str(Commiter[1])+"\");"
    dbcursor_.execute(query)
 
 
def updateCommitTable(Commit):
    query="INSERT INTO Commit (pk_cmitID,cmitTime,fk_cmterID,cmitProperties,cmitComment,cmitCommentLines,fk_projID) VALUES (" \
             +str(Commit[0])+",\""+str(Commit[1])+"\","+str(Commit[2])+",\""+str(Commit[3])+"\",\""+str(Commit[4])+"\","+str(Commit[5])+","+str(Commit[6])+");"
    dbcursor_.execute(query)
                
                
def updateProjectTable(Project):
  dbcursor_.execute("INSERT INTO Project (pk_projID,projName,projWebsite,projContactPoint,projSrcPath,projMailPath) VALUES (" \
                         +str(Project[0])+",\""+str(Project[1])+"\",\""+str(Project[2])+"\",\""+str(Project[3])+"\",\""+str(Project[4])+"\",\""+str(Project[5])+"\");")


def updateProjectVersionTable(ProjectVersion):
  dbcursor_.execute("INSERT INTO ProjectVersion (pfk_projID,projName,projVersion) VALUES (" \
                          +str(ProjectVersion[0])+",\""+str(ProjectVersion[1])+"\",\""+str(ProjectVersion[2])+"\");");



def getLogsLoop():
    
   while svnLogging_.getCurrentRevisionNumber()!=svnLogging_.getLatestRevisionNumber():        

     try:
        entryList_=svnLogging_.getNextLogs(PIVOT);
     except HeadRevisionReachedException:
        print "Attempting to go over the HEAD revision..."
            
     for entry in entryList_:
        print "processing new SVN entry..."
        processLogEntry(entry)

     entryList_.clear()            
            

def processLogEntry(entry):


   revision = int(entry.getRevision())
   commiter = str(entry.getAuthor())  
   datetime = getTimeStamp(entry.getDate()) 
   message = str(entry.getMessage())        
        
   Commiter_[0] = cmterID_ //HERE's THE PROBLEM
   Commiter_[1] = commiter
   updateCommiterTable(Commiter_)
        
    
   Commit_[0] = revision    
   Commit_[1] = datetime    
   Commit_[2] = cmterID_ 
   Commit_[3] = "" #properties
   Commit_[4] = message     
   Commit_[5] = getNumberOfLines(message) 
   Commit_[6] = projID_
   updateCommitTable(Commit_)

   ProjectVersion_[0]=projID_
   ProjectVersion_[1]=""
   ProjectVersion_[2]=""
   updateProjectVersionTable(ProjectVersion_)
        
   Project_[0]=projID_
   Project_[1]=""
   Project_[2]=""
   Project_[3]=""
   Project_[4]=""             
   Project_[5]=""                
   updateProjectTable(Project_)                                      
            
   cmterID_+=1            
   projID_+1
    
##############################HELPER##METHODS###############################    
...        
##############################HELPER##METHODS###############################    

getLogsLoop()
And I get:
Code:
Traceback (innermost last):
  File "ParseSVN2DB.py", line 182, in ?
  File "ParseSVN2DB.py", line 87, in getLogsLoop
  File "ParseSVN2DB.py", line 100, in processLogEntry
UnboundLocalError: local: 'cmterID_'
The things is, that cmterID_ has been instantiated... I don't understand.
Can somebody please explain?

Last edited by kpachopoulos; 09-09-2007 at 03:27 PM. Reason: commented the errors
 
Old 09-10-2007, 09:06 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
try putting the global keyword in your function
Code:
def processLogEntry(entry):
    global cmterID_ 
    ....
    ...
 
  


Reply

Tags
python


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python question gamehack Programming 5 01-03-2005 06:21 AM
Python question bluefire Programming 5 09-28-2004 01:30 PM
python question ywchen2000 Programming 1 04-21-2004 12:46 AM
A Python question gamehack Programming 2 03-17-2004 10:09 PM
Python question m4rccd Programming 1 08-24-2003 07:04 AM


All times are GMT -5. The time now is 01:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration