* 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"?>
|
||||
<!DOCTYPE Project SYSTEM "Project-3.8.dtd">
|
||||
<!-- 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 -->
|
||||
<Project version="3.8">
|
||||
<ProgLanguage mixed="0">Python</ProgLanguage>
|
||||
@@ -408,6 +408,10 @@
|
||||
<Dir>tests</Dir>
|
||||
<Name>sandbox</Name>
|
||||
</Other>
|
||||
<Other>
|
||||
<Dir>tests</Dir>
|
||||
<Name>beta-remoterepo.sh</Name>
|
||||
</Other>
|
||||
</Others>
|
||||
<MainScript>
|
||||
<Name>pisi-cli</Name>
|
||||
@@ -419,9 +423,9 @@
|
||||
</Vcs>
|
||||
<FiletypeAssociations>
|
||||
<FiletypeAssociation pattern="*.ui.h" type="FORMS" />
|
||||
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
||||
<FiletypeAssociation pattern="*.ui" type="FORMS" />
|
||||
<FiletypeAssociation pattern="*.idl" type="INTERFACES" />
|
||||
<FiletypeAssociation pattern="*.ptl" type="SOURCES" />
|
||||
<FiletypeAssociation pattern="*.py" type="SOURCES" />
|
||||
</FiletypeAssociations>
|
||||
</Project>
|
||||
|
||||
+2
-1
@@ -28,7 +28,8 @@ import pisi.context as ctx
|
||||
import pisi.dependency as dependency
|
||||
import pisi.operations as operations
|
||||
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.package import Package
|
||||
|
||||
|
||||
+14
-75
@@ -15,93 +15,32 @@
|
||||
|
||||
# Authors: Eray Ozkural <eray@uludag.org.tr>
|
||||
|
||||
from pisi.xmlext import *
|
||||
from pisi.xmlfile import XmlFile
|
||||
import pisi.xmlfile as xmlfile
|
||||
from pisi.util import Checks
|
||||
import pisi.lockeddbshelve as shelve
|
||||
|
||||
class FileInfo:
|
||||
"""FileInfo 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
|
||||
class File:
|
||||
"""File holds the information for a File node/tag in files.xml"""
|
||||
|
||||
def readnew(node):
|
||||
f = FileInfo()
|
||||
f.read(node)
|
||||
return f
|
||||
readnew = staticmethod(readnew)
|
||||
__metaclass__ = xmlfile.autoxml
|
||||
|
||||
def read(self, node):
|
||||
self.path = getNodeText(getNode(node, "Path"))
|
||||
self.type = getNodeText(getNode(node, "Type"))
|
||||
self.size = getNodeText(getNode(node, "Size"))
|
||||
hashnode = getNode(node, "SHA1Sum")
|
||||
if hashnode:
|
||||
self.hash = getNodeText(hashnode)
|
||||
else:
|
||||
self.hash = None
|
||||
t_Path = [ xmlfile.String, xmlfile.mandatory ]
|
||||
t_Type = [ xmlfile.String, xmlfile.mandatory ]
|
||||
t_Size = [ xmlfile.Integer, xmlfile.mandatory ]
|
||||
t_Hash = [ xmlfile.String, xmlfile.optional, "SHA1Sum" ]
|
||||
|
||||
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):
|
||||
s = "%s, type: %s, size: %s, sha1sum: %s" % (self.path, self.type,
|
||||
self.size, self.hash)
|
||||
return s
|
||||
|
||||
class Files(XmlFile):
|
||||
|
||||
def __init__(self):
|
||||
XmlFile.__init__(self, "Files")
|
||||
self.list = []
|
||||
class Files(xmlfile.XmlFile):
|
||||
|
||||
def append(self, fileinfo):
|
||||
self.list.append(fileinfo)
|
||||
__metaclass__ = xmlfile.autoxml
|
||||
|
||||
def read(self, filename):
|
||||
self.readxml(filename)
|
||||
tag = "Files"
|
||||
|
||||
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
|
||||
t_List = [ [File], xmlfile.optional, "File"]
|
||||
|
||||
class FilesDB(shelve.LockedDBShelf):
|
||||
|
||||
@@ -113,8 +52,8 @@ class FilesDB(shelve.LockedDBShelf):
|
||||
self[str(x.path)] = (pkg_name, x)
|
||||
|
||||
def remove_files(self, files):
|
||||
for x in files.list:
|
||||
self.delete(str(x.path))
|
||||
for x in files.list:
|
||||
self.delete(str(x.path))
|
||||
|
||||
def has_file(self, path):
|
||||
return self.has_key(str(path))
|
||||
|
||||
+6
-5
@@ -292,9 +292,8 @@ class autoxml(oo.autosuper, oo.autoprop):
|
||||
|
||||
# generate top-level helper functions
|
||||
cls.initializers = inits
|
||||
def initialize(self, tag = None, spec = None):
|
||||
#FIXME: what the hell is spec? :(
|
||||
if not tag:
|
||||
def initialize(self, **args):
|
||||
if not args.has_key('tag'):
|
||||
tag = cls.tag
|
||||
if xmlfile_support:
|
||||
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
|
||||
for init in inits:#self.__class__.initializers:
|
||||
init(self)
|
||||
for x in args.iterkeys():
|
||||
setattr(self, x, args[x])
|
||||
# init hook
|
||||
if hasattr(self, 'init'):
|
||||
self.init(tag)
|
||||
@@ -613,7 +614,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
||||
|
||||
def make_object():
|
||||
obj = tag_type.__new__(tag_type)
|
||||
obj.__init__(tag, spec)
|
||||
obj.__init__(tag=tag, req=req)
|
||||
return obj
|
||||
|
||||
def init():
|
||||
@@ -728,7 +729,7 @@ class autoxml(oo.autosuper, oo.autoprop):
|
||||
|
||||
def make_object():
|
||||
obj = tag_type.__new__(tag_type)
|
||||
obj.__init__(tag, spec)
|
||||
obj.__init__(tag=tag, req=req)
|
||||
return obj
|
||||
|
||||
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