* add keyword arg initialization to autoxml init
* automxlize Files * a simple test for files module
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
|
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
|
||||||
<!-- Project file for project pisi -->
|
<!-- Project file for project pisi -->
|
||||||
<!-- Saved: 2005-11-03, 02:14:40 -->
|
<!-- Saved: 2005-11-03, 20:18:56 -->
|
||||||
<!-- Copyright (C) 2005 PiSi Development Team, pisi@uludag.org.tr -->
|
<!-- Copyright (C) 2005 PiSi Development Team, pisi@uludag.org.tr -->
|
||||||
<Project version="3.8">
|
<Project version="3.8">
|
||||||
<ProgLanguage mixed="0">Python</ProgLanguage>
|
<ProgLanguage mixed="0">Python</ProgLanguage>
|
||||||
@@ -408,6 +408,10 @@
|
|||||||
<Dir>tests</Dir>
|
<Dir>tests</Dir>
|
||||||
<Name>sandbox</Name>
|
<Name>sandbox</Name>
|
||||||
</Other>
|
</Other>
|
||||||
|
<Other>
|
||||||
|
<Dir>tests</Dir>
|
||||||
|
<Name>beta-remoterepo.sh</Name>
|
||||||
|
</Other>
|
||||||
</Others>
|
</Others>
|
||||||
<MainScript>
|
<MainScript>
|
||||||
<Name>pisi-cli</Name>
|
<Name>pisi-cli</Name>
|
||||||
@@ -419,9 +423,9 @@
|
|||||||
</Vcs>
|
</Vcs>
|
||||||
<FiletypeAssociations>
|
<FiletypeAssociations>
|
||||||
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
||||||
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
|
||||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
|
||||||
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
||||||
|
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
||||||
|
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
||||||
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
||||||
</FiletypeAssociations>
|
</FiletypeAssociations>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
+2
-1
@@ -28,7 +28,8 @@ import pisi.context as ctx
|
|||||||
import pisi.dependency as dependency
|
import pisi.dependency as dependency
|
||||||
import pisi.operations as operations
|
import pisi.operations as operations
|
||||||
from pisi.sourcearchive import SourceArchive
|
from pisi.sourcearchive import SourceArchive
|
||||||
from pisi.files import Files, FileInfo
|
from pisi.files import Files, File as FileInfo
|
||||||
|
from pisi.files import Files
|
||||||
from pisi.metadata import MetaData
|
from pisi.metadata import MetaData
|
||||||
from pisi.package import Package
|
from pisi.package import Package
|
||||||
|
|
||||||
|
|||||||
+14
-75
@@ -15,93 +15,32 @@
|
|||||||
|
|
||||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||||
|
|
||||||
from pisi.xmlext import *
|
import pisi.xmlfile as xmlfile
|
||||||
from pisi.xmlfile import XmlFile
|
|
||||||
from pisi.util import Checks
|
from pisi.util import Checks
|
||||||
import pisi.lockeddbshelve as shelve
|
import pisi.lockeddbshelve as shelve
|
||||||
|
|
||||||
class FileInfo:
|
class File:
|
||||||
"""FileInfo holds the information for a File node/tag in files.xml"""
|
"""File holds the information for a File node/tag in files.xml"""
|
||||||
def __init__(self, _path = "", _type = "", _size = "", _hash = None):
|
|
||||||
self.path = _path
|
|
||||||
self.type = _type
|
|
||||||
self.size = _size
|
|
||||||
self.hash = _hash
|
|
||||||
|
|
||||||
def readnew(node):
|
__metaclass__ = xmlfile.autoxml
|
||||||
f = FileInfo()
|
|
||||||
f.read(node)
|
|
||||||
return f
|
|
||||||
readnew = staticmethod(readnew)
|
|
||||||
|
|
||||||
def read(self, node):
|
t_Path = [ xmlfile.String, xmlfile.mandatory ]
|
||||||
self.path = getNodeText(getNode(node, "Path"))
|
t_Type = [ xmlfile.String, xmlfile.mandatory ]
|
||||||
self.type = getNodeText(getNode(node, "Type"))
|
t_Size = [ xmlfile.Integer, xmlfile.mandatory ]
|
||||||
self.size = getNodeText(getNode(node, "Size"))
|
t_Hash = [ xmlfile.String, xmlfile.optional, "SHA1Sum" ]
|
||||||
hashnode = getNode(node, "SHA1Sum")
|
|
||||||
if hashnode:
|
|
||||||
self.hash = getNodeText(hashnode)
|
|
||||||
else:
|
|
||||||
self.hash = None
|
|
||||||
|
|
||||||
def elt(self, dom):
|
|
||||||
## FIXME: looking for a better way to do it
|
|
||||||
## could apparently use helper functions to do this shorter
|
|
||||||
elt = dom.createElement("File")
|
|
||||||
pathElt = dom.createElement("Path")
|
|
||||||
pathElt.appendChild(dom.createTextNode(self.path))
|
|
||||||
elt.appendChild(pathElt)
|
|
||||||
typeElt = dom.createElement("Type")
|
|
||||||
typeElt.appendChild(dom.createTextNode(self.type))
|
|
||||||
elt.appendChild(typeElt)
|
|
||||||
if self.size:
|
|
||||||
sizeElt = dom.createElement("Size")
|
|
||||||
sizeElt.appendChild(dom.createTextNode(self.size))
|
|
||||||
elt.appendChild(sizeElt)
|
|
||||||
if self.hash:
|
|
||||||
hashElt = dom.createElement("SHA1Sum")
|
|
||||||
hashElt.appendChild(dom.createTextNode(self.hash))
|
|
||||||
elt.appendChild(hashElt)
|
|
||||||
return elt
|
|
||||||
|
|
||||||
def has_errors(self):
|
|
||||||
err = Checks()
|
|
||||||
err.has_tag(self.path, "File", "Path")
|
|
||||||
err.has_tag(self.type, "File", "Type")
|
|
||||||
return err.list
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
s = "%s, type: %s, size: %s, sha1sum: %s" % (self.path, self.type,
|
s = "%s, type: %s, size: %s, sha1sum: %s" % (self.path, self.type,
|
||||||
self.size, self.hash)
|
self.size, self.hash)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
class Files(XmlFile):
|
class Files(xmlfile.XmlFile):
|
||||||
|
|
||||||
def __init__(self):
|
__metaclass__ = xmlfile.autoxml
|
||||||
XmlFile.__init__(self, "Files")
|
|
||||||
self.list = []
|
|
||||||
|
|
||||||
def append(self, fileinfo):
|
tag = "Files"
|
||||||
self.list.append(fileinfo)
|
|
||||||
|
|
||||||
def read(self, filename):
|
t_List = [ [File], xmlfile.optional, "File"]
|
||||||
self.readxml(filename)
|
|
||||||
|
|
||||||
fileElts = self.getAllNodes("File")
|
|
||||||
self.list = [FileInfo.readnew(x) for x in fileElts]
|
|
||||||
|
|
||||||
def write(self, filename):
|
|
||||||
self.newDOM()
|
|
||||||
document = self.dom.documentElement
|
|
||||||
for x in self.list:
|
|
||||||
document.appendChild(x.elt(self.dom))
|
|
||||||
self.writexml(filename)
|
|
||||||
|
|
||||||
def has_errors(self):
|
|
||||||
err = Checks()
|
|
||||||
for finfo in self.list:
|
|
||||||
err.join(finfo.has_errors())
|
|
||||||
return err.list
|
|
||||||
|
|
||||||
class FilesDB(shelve.LockedDBShelf):
|
class FilesDB(shelve.LockedDBShelf):
|
||||||
|
|
||||||
@@ -113,8 +52,8 @@ class FilesDB(shelve.LockedDBShelf):
|
|||||||
self[str(x.path)] = (pkg_name, x)
|
self[str(x.path)] = (pkg_name, x)
|
||||||
|
|
||||||
def remove_files(self, files):
|
def remove_files(self, files):
|
||||||
for x in files.list:
|
for x in files.list:
|
||||||
self.delete(str(x.path))
|
self.delete(str(x.path))
|
||||||
|
|
||||||
def has_file(self, path):
|
def has_file(self, path):
|
||||||
return self.has_key(str(path))
|
return self.has_key(str(path))
|
||||||
|
|||||||
+6
-5
@@ -292,9 +292,8 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
|
|
||||||
# generate top-level helper functions
|
# generate top-level helper functions
|
||||||
cls.initializers = inits
|
cls.initializers = inits
|
||||||
def initialize(self, tag = None, spec = None):
|
def initialize(self, **args):
|
||||||
#FIXME: what the hell is spec? :(
|
if not args.has_key('tag'):
|
||||||
if not tag:
|
|
||||||
tag = cls.tag
|
tag = cls.tag
|
||||||
if xmlfile_support:
|
if xmlfile_support:
|
||||||
XmlFile.__init__(self, tag = tag)
|
XmlFile.__init__(self, tag = tag)
|
||||||
@@ -303,6 +302,8 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
#super(cls, self).__init__(tag = tag) cooperative shit disabled for now
|
#super(cls, self).__init__(tag = tag) cooperative shit disabled for now
|
||||||
for init in inits:#self.__class__.initializers:
|
for init in inits:#self.__class__.initializers:
|
||||||
init(self)
|
init(self)
|
||||||
|
for x in args.iterkeys():
|
||||||
|
setattr(self, x, args[x])
|
||||||
# init hook
|
# init hook
|
||||||
if hasattr(self, 'init'):
|
if hasattr(self, 'init'):
|
||||||
self.init(tag)
|
self.init(tag)
|
||||||
@@ -613,7 +614,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
|
|
||||||
def make_object():
|
def make_object():
|
||||||
obj = tag_type.__new__(tag_type)
|
obj = tag_type.__new__(tag_type)
|
||||||
obj.__init__(tag, spec)
|
obj.__init__(tag=tag, req=req)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
@@ -728,7 +729,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
|||||||
|
|
||||||
def make_object():
|
def make_object():
|
||||||
obj = tag_type.__new__(tag_type)
|
obj = tag_type.__new__(tag_type)
|
||||||
obj.__init__(tag, spec)
|
obj.__init__(tag=tag, req=req)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Copyright (C) 2005, TUBITAK/UEKAE
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License as published by the Free
|
||||||
|
# Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
#
|
||||||
|
# Please read the COPYING file.
|
||||||
|
#
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
import os
|
||||||
|
|
||||||
|
import pisi.context as ctx
|
||||||
|
import pisi.api
|
||||||
|
import pisi.installdb
|
||||||
|
import pisi.files as files
|
||||||
|
from pisi import util
|
||||||
|
|
||||||
|
import testcase
|
||||||
|
|
||||||
|
class FilesTestCase(testcase.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
testcase.TestCase.setUp(self, database=False)
|
||||||
|
|
||||||
|
def testFileInfo(self):
|
||||||
|
f1 = files.File(path = '/usr/bin/zibidi')
|
||||||
|
f2 = files.File(path = '/usr/bin/kopus', type='exec', size=13, hash="abugubu")
|
||||||
|
|
||||||
|
suite = unittest.makeSuite(FilesTestCase)
|
||||||
Reference in New Issue
Block a user