ajack 2004/02/24 11:32:28
Modified: python/gump/test tools.py __init__.py
python/gump engine.py
python/gump/utils tools.py
python/gump/document resolver.py forrest.py
python/gump/model object.py project.py
python/gump/test/resources/full1 profile.xml
Added: python/gump/utils file.py
Removed: python/gump/storage logic.py
Log:
1) Starting the migration to pure Python (whenever possible).
2) Fixed the unit test complaining about no trackers
3) Removed logic.py, obsolete.
Revision Changes Path
1.4 +21 -0 jakarta-gump/python/gump/test/tools.py
Index: tools.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/test/tools.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- tools.py 9 Jan 2004 19:57:19 -0000 1.3
+++ tools.py 24 Feb 2004 19:32:28 -0000 1.4
@@ -62,8 +62,15 @@
"""
from gump.utils.tools import *
+from gump.utils.work import *
+from gump.utils.file import *
from gump.test.pyunit import UnitTestSuite
+class TestFileHolder(FileHolder):
+ def __init__(self):
+ # Holds work (with state)
+ FileHolder.__init__(self)
+
class TestWorkable(Workable):
def __init__(self):
# Holds work (with state)
@@ -75,6 +82,7 @@
def suiteSetUp(self):
self.testworkable=TestWorkable()
+ self.testfileholder=TestFileHolder()
def testListAsWork(self):
listDirectoryAsWork(self.testworkable,'.','test')
@@ -88,4 +96,17 @@
# :TODO: Move to work unit tests module (once written)
def testWorkClone(self):
self.testworkable.getWorkList().clone()
+
+
+ def testListToFileHolder(self):
+ listDirectoryToFileHolder(self.testfileholder,'.','test')
+
+ def testCatFileToFileHolder(self):
+ catFileToFileHolder(self.testfileholder,'./text.xml','test')
+
+ def testCatDirToFileHolder(self):
+ catDirectoryContentsToFileHolder(self.testfileholder,'.','test')
+
+ def testFileClone(self):
+ self.testfileholder.getFileList().clone()
1.8 +4 -4 jakarta-gump/python/gump/test/__init__.py
Index: __init__.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/test/__init__.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- __init__.py 9 Jan 2004 19:57:19 -0000 1.7
+++ __init__.py 24 Feb 2004 19:32:28 -0000 1.8
@@ -72,7 +72,7 @@
from gump.model.workspace import Workspace
from gump.output.statsdb import StatisticsDB
-from gump.utils.tools import listDirectoryAsWork
+from gump.utils.tools import listDirectoryToFileHolder
def getTestWorkspace(xml=None):
if not xml: xml='gump/test/resources/full1/workspace.xml'
@@ -91,11 +91,11 @@
db.loadStatistics(workspace)
# Some work items...
- listDirectoryAsWork(workspace,workspace.getBaseDirectory())
+ listDirectoryToFileHolder(workspace,workspace.getBaseDirectory())
for module in workspace.getModules():
- listDirectoryAsWork(module,module.getSourceDirectory())
+ listDirectoryToFileHolder(module,module.getSourceDirectory())
for project in module.getProjects():
- listDirectoryAsWork(project,project.getHomeDirectory())
+ listDirectoryToFileHolder(project,project.getHomeDirectory())
#
# Try to set some statii
1.60 +5 -5 jakarta-gump/python/gump/engine.py
Index: engine.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/engine.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- engine.py 23 Feb 2004 21:55:35 -0000 1.59
+++ engine.py 24 Feb 2004 19:32:28 -0000 1.60
@@ -524,7 +524,7 @@
project.addDebug('Maven Properties in: ' + propertiesFile)
try:
- catFileAsWork(project,propertiesFile, \
+ catFileToFileHolder(project,propertiesFile, \
project.getName() + ' ' + os.path.basename(propertiesFile))
except:
log.error('Display Properties [ ' + propertiesFile + ']
Failed', exc_info=1)
@@ -605,7 +605,7 @@
project.changeState(STATE_SUCCESS)
# For 'fun' list repository
-
listDirectoryAsWork(project,repository.getGroupDir(project.getModule().getName()), \
+
listDirectoryToFileHolder(project,repository.getGroupDir(project.getModule().getName()),
\
'list_repo_'+project.getName())
if not outputsOk:
@@ -621,7 +621,7 @@
if not dir in dirs:
dircnt += 1
if os.path.exists(dir):
- listDirectoryAsWork(project,dir,\
+ listDirectoryToFileHolder(project,dir,\
'list_'+project.getName()+'_dir'+str(dircnt)+'_'+os.path.basename(dir))
dirs.append(dir)
listed += 1
@@ -641,7 +641,7 @@
for report in project.getReports():
reportDir=report.getResolvedPath()
project.addInfo('Reports in: ' + reportDir)
- catDirectoryContentsAsWork(project,reportDir)
+ catDirectoryContentsToFileHolder(project,reportDir)
# Maven generates a maven.log...
if project.hasMaven() and not project.isPackaged():
@@ -649,7 +649,7 @@
logFile=project.locateMavenLog()
project.addDebug('Maven Log in: ' + logFile)
try:
- catFileAsWork(project,logFile, \
+ catFileToFileHolder(project,logFile, \
project.getName() + ' ' + os.path.basename(logFile))
except:
log.error('Display Log [ ' + logFile + '] Failed', exc_info=1)
1.11 +55 -3 jakarta-gump/python/gump/utils/tools.py
Index: tools.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/utils/tools.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- tools.py 19 Jan 2004 20:16:59 -0000 1.10
+++ tools.py 24 Feb 2004 19:32:28 -0000 1.11
@@ -67,6 +67,7 @@
from gump import log
from gump.utils.work import *
+from gump.utils.file import *
from gump.utils.launcher import *
def listDirectoryAsWork(workable,directory,name=None):
@@ -123,6 +124,57 @@
workable.performedWork(CommandWorkItem(WORK_TYPE_DOCUMENT,cmd,result))
return ok
+
+def listDirectoryToFileHolder(holder,directory,type=FILE_TYPE_MISC):
+
+ # Create a reference to the directory
+ reference=FileReference(directory,type)
+
+ #
+ # Update holder w/ reference to directory, 'listing'
+ # is implied (from it being a directory)
+ #
+ holder.addFileReference(reference)
+
+ #
+ # This is 'ok', if it exists, and is a directory
+ #
+ return reference.exists() and reference.isDirectory()
+
+def catDirectoryContentsToFileHolder(holder,directory,name=None):
+ try:
+ if os.path.exists(directory) and os.path.isdir(directory):
+ for fileName in os.listdir(directory):
+ baseName=name
+ file=os.path.abspath(os.path.join(directory,fileName))
+ if os.path.exists(file) and os.path.isfile(file):
+ if baseName:
+ workName=baseName+'_'+fileName
+ else:
+ workName=fileName
+ catFileToFileHolder(holder, file, workName)
+ except:
+ try:
+ holder.addWarning('No such directory [' + str(directory) + ']')
+ except:
+ pass
+
+
+def catFileToFileHolder(holder,file,name=None):
+
+ # Create a reference to the file
+ reference=FileReference(file,type)
+
+ #
+ # Update holder w/ reference to directory, 'cat'
+ # is implied (from it being a file)
+ #
+ holder.addFileReference(reference)
+
+ #
+ # This is 'ok', if it exists, and is not a directory
+ #
+ return reference.exists() and reference.isNotDirectory()
def syncDirectories(noRSync,type,cwddir,tmpdir,sourcedir,destdir,name=None):
1.1 jakarta-gump/python/gump/utils/file.py
Index: file.py
===================================================================
#!/usr/bin/env python
# $Header: /home/cvs/jakarta-gump/python/gump/utils/work.py,v 1.9 2004/02/17
21:54:21 ajack Exp $
# $Revision: 1.9 $
# $Date: 2004/02/17 21:54:21 $
#
# ====================================================================
#
# The Apache Software License, Version 1.1
#
# Copyright (c) 2003 The Apache Software Foundation. All rights
# reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# 3. The end-user documentation included with the redistribution, if
# any, must include the following acknowlegement:
# "This product includes software developed by the
# Apache Software Foundation (http://www.apache.org/)."
# Alternately, this acknowlegement may appear in the software itself,
# if and wherever such third-party acknowlegements normally appear.
#
# 4. The names "The Jakarta Project", "Alexandria", and "Apache Software
# Foundation" must not be used to endorse or promote products derived
# from this software without prior written permission. For written
# permission, please contact [EMAIL PROTECTED]
#
# 5. Products derived from this software may not be called "Apache"
# nor may "Apache" appear in their names without prior written
# permission of the Apache Group.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
# ====================================================================
#
# This software consists of voluntary contributions made by many
# individuals on behalf of the Apache Software Foundation. For more
# information on the Apache Software Foundation, please see
# <http://www.apache.org/>.
"""
This module contains information on
"""
import os
import os.path
from time import localtime, strftime, tzname
from string import lower, capitalize
from gump.utils.note import *
from gump.utils.owner import *
FILE_TYPE_MISC=1
FILE_TYPE_CONFIG=2
FILE_TYPE_OUTPUT=3
fileTypeDescriptions = { FILE_TYPE_MISC : "Miscellaneous",
FILE_TYPE_CONFIG : "Config",
FILE_TYPE_OUTPUT : "Output", }
def fileTypeName(type):
return fileTypeDescriptions.get(type,'Unknown File Type:' + str(type))
class FileReference(Ownable,Annotatable):
""" Unit of File"""
def __init__(self,path,type=FILE_TYPE_MISC,name=None,message=''):
Ownable.__init__(self)
Annotatable.__init__(self)
self.path=path
self.type=type
# Extract a name, or basename
if name:
self.name=name
else:
self.name=os.path.basename(path)
if message:
self.addInfo(message)
def overview(self, lines=50):
overview='File Name: ' + self.name +' (Type: ' +
fileTypeName(self.type)+')\n'
#
# :TODO: Annotations....
#
if self.path and os.path.exists(self.path):
overview += "---------------------------------------------\n"
from gump.utils.tools import tailFileToString
overview += tailFileToString(self.path,lines)
overview += "---------------------------------------------\n"
return overview
def exists(self):
return os.path.exists(self.path)
def isDirectory(self):
return os.path.isdir(self.path)
def isNotDirectory(self):
return not os.path.isdir(self.path)
def getType(self):
return self.type
def getTypeName(self):
return fileTypeName(self.type)
def getName(self):
return self.name
def setName(self,name):
self.name=name
def clone(self):
cloned=FileReference(self.path,self.type,self.name)
# :TODO: Transfer annotations?
return cloned
class FileList(list,Ownable):
"""List of file (in order)"""
def __init__(self,owner=None):
list.__init__(self)
Ownable.__init__(self,owner)
# Organize by name
self.nameIndex={}
def add(self,reference):
if reference.hasOwner():
# :TODO: Clone ...... ????????
raise RuntimeError, 'FileReference already owned, can\'t add to list'
# Keep unique within the scope of this list
name=reference.getName()
uniquifier=1
while self.nameIndex.has_key(name):
name=reference.getName()+str(uniquifier)
uniquifier+=1
reference.setName(name)
# Store by name
self.nameIndex[name]=reference
# Store in the list
self.append(reference)
# Let this reference know it's owner
reference.setOwner(self.getOwner())
def clone(self):
cloned=FileList()
for reference in self:
cloned.add(reference.clone())
return cloned
class FileHolder:
def __init__(self):
self.filelist=FileList(self)
def getFileList(self):
return self.filelist
def addFileReference(self,fileReference):
self.filelist.add(fileReference)
def addFile(self,path):
self.filelist.add(FileReference(path))
1.14 +11 -5 jakarta-gump/python/gump/document/resolver.py
Index: resolver.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/document/resolver.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- resolver.py 15 Feb 2004 17:32:05 -0000 1.13
+++ resolver.py 24 Feb 2004 19:32:28 -0000 1.14
@@ -76,6 +76,8 @@
from gump.output.statsdb import StatisticsGuru
from gump.output.xref import XRefGuru
+from gump.utils.work import *
+from gump.utils.file import *
from gump.model.repository import Repository
from gump.model.server import Server
from gump.model.tracker import Tracker
@@ -156,7 +158,9 @@
elif isinstance(object, Project):
path=getPathForObject(object.getModule())
elif isinstance(object, WorkItem):
- path=getPathForObject(object.getOwner()).getPostfixed('work')
+ path=getPathForObject(object.getOwner()).getPostfixed('gump_work')
+ elif isinstance(object, FileReference):
+ path=getPathForObject(object.getOwner()).getPostfixed('gump_file')
elif isinstance(object, Ownable):
if not object.getOwner() in visited:
path=getPathForObject(object.getOwner())
@@ -241,6 +245,7 @@
or isinstance(object, Server) \
or isinstance(object, Tracker) \
or isinstance(object, Repository) \
+ or isinstance(object, FileReference) \
or isinstance(object, WorkItem):
document=gumpSafeName(object.getName()) + extn
elif isinstance(object, Ownable) :
@@ -263,7 +268,8 @@
isinstance(object, XRefGuru) or \
isinstance(object, Module) or \
isinstance(object, Project) or \
- isinstance(object, Work):
+ isinstance(object, WorkItem) or \
+ isinstance(object, FileReference):
index=None
elif isinstance(object, Ant):
index='Build'
1.80 +94 -4 jakarta-gump/python/gump/document/forrest.py
Index: forrest.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/document/forrest.py,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -r1.79 -r1.80
--- forrest.py 23 Feb 2004 21:55:35 -0000 1.79
+++ forrest.py 24 Feb 2004 19:32:28 -0000 1.80
@@ -1609,6 +1609,96 @@
wdocument.serialize()
wdocument=None
+
+ def documentFileList(self,xdocNode,holder,description='Files'):
+ filelist=holder.getFileList()
+
+ if not filelist: return
+
+ fileSection=xdocNode.createSection(description)
+ fileTable=fileSection.createTable(['Name','Type','PAth'])
+
+ for file in filelist:
+ fileRow=fileTable.createRow()
+ fileRow.createComment(file.getName())
+ self.insertLink(file,holder,fileRow.createData())
+ fileRow.createData(fileTypeDescription(file.getType()))
+ fileRow.createData(file.getPath())
+
+ #
+ # Go document the others...
+ #
+ for fileReference in filelist:
+ self.documentFile(workspace,fileReference)
+
+ def documentFile(self,workspace,fileReference):
+
+ fdocument=XDocDocument( \
+ fileTypeName(fileReference.getType()) + ' : ' +
fileReference.getName(), \
+ self.resolver.getFile(fileReference))
+
+ fileSection=fdocument.createSection('Details')
+
+ fileList=fileSection.createList()
+ fileList.createEntry("State: ", fileTypeName(fileReference.getType()))
+
+ self.insertTypedLink(fileReference.getOwner(), \
+ fileReference, \
+ fileList.createEntry("For: "))
+
+ if fileReference.exists():
+ if fileReference.isDirectory():
+ listingSection=fdocument.createSection('Directory Contents')
+ listingTable=listingSection.createTable(['Filename'])
+
+ directory=fileReference.getPath()
+
+ # Change to os.walk once we can move to Python 2.3
+ files=os.listdir(directory).sort()
+ for file in files:
+ listingRow=listingTable.createRow()
+ listingRow.createData(file)
+
+ else:
+ #
+ # Show the content...
+ #
+ outputSection=fdocument.createSection('Output')
+ outputSource=outputSection.createSource()
+ output=fileReference.getPath()
+ if output:
+ try:
+ o=None
+ try:
+ # Keep a length count to not exceed 32K
+ size=0
+ o=open(output, 'r')
+ line=o.readline()
+ while line:
+
+ line=wrapLine(line,'...<br/>',' ',100)
+
+ length = len(line)
+ size += length
+ # Crude to 'ensure' that escaped
+ # it doesn't exceed 32K.
+ if size > 20000:
+ outputSection.createParagraph('Continuation...')
+ outputSource=outputSection.createSource()
+ size = length
+ outputSource.createText(line)
+ line=o.readline()
+ finally:
+ if o: o.close()
+ except Exception, details:
+ outputSource.createText('Failed to copy contents from :' +
output + ' : ' + str(details))
+ else:
+ outputSource.createText('No contents in this file.')
+ else:
+ fdocument.createText('No such file or directory.')
+
+ fdocument.serialize()
+ fdocument=None
#####################################################################
#
@@ -1688,7 +1778,7 @@
#
# If we are looking for what set the state, look at
- # work first. Pick the first...
+ # work first. Pick the first not working...
#
if state and isinstance(toObject,Workable):
for work in toObject.getWorkList():
1.18 +8 -4 jakarta-gump/python/gump/model/object.py
Index: object.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/model/object.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- object.py 17 Feb 2004 21:54:20 -0000 1.17
+++ object.py 24 Feb 2004 19:32:28 -0000 1.18
@@ -67,6 +67,7 @@
from gump.utils.note import *
from gump.utils.work import *
+from gump.utils.file import *
from gump.utils.owner import *
from gump.utils.xmlutils import xmlize
@@ -145,12 +146,15 @@
return self.causes
-class ModelObject(Annotatable,Workable,Propogatable,Ownable):
+class ModelObject(Annotatable,Workable,FileHolder,Propogatable,Ownable):
"""Base model object for a single entity"""
def __init__(self,xml,owner=None):
# Can scribble on this thing...
Annotatable.__init__(self)
+
+ # Holds file references
+ FileHolder.__init__(self)
# Holds work (with state)
Workable.__init__(self)
1.55 +5 -5 jakarta-gump/python/gump/model/project.py
Index: project.py
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/model/project.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- project.py 23 Feb 2004 17:00:05 -0000 1.54
+++ project.py 24 Feb 2004 19:32:28 -0000 1.55
@@ -612,8 +612,8 @@
#
# List them, why not...
#
- from gump.utils.tools import listDirectoryAsWork
- listDirectoryAsWork(self,self.getHomeDirectory(), \
+ from gump.utils.tools import listDirectoryToFileHolder
+ listDirectoryToFileHolder(self,self.getHomeDirectory(), \
'list_package_'+self.getName())
def importDependencies(self,workspace):
1.8 +1 -1 jakarta-gump/python/gump/test/resources/full1/profile.xml
Index: profile.xml
===================================================================
RCS file: /home/cvs/jakarta-gump/python/gump/test/resources/full1/profile.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- profile.xml 17 Feb 2004 21:54:21 -0000 1.7
+++ profile.xml 24 Feb 2004 19:32:28 -0000 1.8
@@ -18,7 +18,7 @@
<server href="server1.xml"/>
- <server href="tracker1.xml"/>
+ <tracker href="tracker1.xml"/>
<!-- Repository definitions -->
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]