diff --git a/pisi/specfilenew.py b/pisi/specfilenew.py new file mode 100644 index 00000000..d6ab0f35 --- /dev/null +++ b/pisi/specfilenew.py @@ -0,0 +1,144 @@ +# -*- coding: utf-8 -*- +# +# 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. +# + +# Specfile module is our handler for PSPEC files. PSPEC (PISI SPEC) +# files are specification files for PISI source packages. This module +# provides read and write access to PSPEC files. + +# Authors: Eray Ozkural +# Baris Metin + +# standard python modules +from os.path import basename + +# pisi modules +from pisi.xmlext import * +import pisi.xmlfile as xmlfile +from pisi.xmlfile import XmlFile +from pisi.ui import ui +from pisi.dependency import DepInfo +from pisi.util import Checks + + +class Packager: + __metaclass__ = xmlfile.autoxml + t_Name = [types.StringType, xmlfile.mandatory] + t_Email = [types.StringType, xmlfile.mandatory] + def __str__(self): + s = "%s <%s>" % (self.name, self.email) + return s +class AdditionalFileInfo: + __metaclass__ = xmlfile.autoxml + + s_Filename = xmlfile.mandatory + a_Target = [types.StringType, xmlfile.mandatory] + a_Permission = [types.StringType, xmlfile.optional] + + def __str__(self): + s = "%s -> %s " % (self.filename, self.target) + if self.permission: + s += '(%s)' % self.permission + return s + +class Patch: + __metaclass__ = xmlfile.autoxml + + s_Filename = xmlfile.mandatory + a_compressionType = [types.StringType, xmlfile.optional] + a_level = [types.StringType, xmlfile.optional] + a_target = [types.StringType, xmlfile.optional] + + def __str__(self): + s = self.filename + if self.compressionType: + s += ' (' + self.compressionType + ')' + if self.level: + s += ' level:' + self.level + if self.target: + s += ' target:' + self.target + return s + +class Update: + __metaclass__ = xmlfile.autoxml + + t_Date = [types.StringType, xmlfile.mandatory] + t_Version = [types.StringType, xmlfile.mandatory] + t_Release = [types.StringType, xmlfile.mandatory] + t_Type = [types.StringType, xmlfile.optional] + + def __str__(self): + s = self.date + s += ", ver=" + self.version + s += ", rel=" + self.release + if self.type: + s += ", type=" + self.type + return s + +class Path: + __metaclass__ = xmlfile.autoxml + s_Path = xmlfile.mandatory + a_fileType = [types.StringType, xmlfile.optional] + def __str__(self): + s = self.pathname + s += ", type=" + self.fileType + return s + + +class ComarProvide: + __metaclass__ = xmlfile.autoxml + s_om = [types.StringType, xmlfile.mandatory] + a_script = [types.StringType, xmlfile.mandatory] + def __str__(self): + # FIXME: descriptive enough? + s = self.script + s += ' (' + self.om + ')' + return s + +class Archive: + __metaclass__ = xmlfile.autoxml + s_uri = [ types.StringType, xmlfile.mandatory ] + a_type =[ types.StringType, xmlfile.mandatory ] + a_sha1sum =[ types.StringType, xmlfile.mandatory ] + + def decode_post(self): + self.name = basename(self.uri) + + +class Source: + __metaclass__ = xmlfile.autoxml + t_Name = [types.StringType, xmlfile.mandatory] + t_HomePage = [types.StringType, xmlfile.mandatory] + t_Packager = [Packager, xmlfile.mandatory] + t_Summary = [types.StringType, xmlfile.mandatory] + t_Description = [types.StringType, xmlfile.mandatory] + t_License = [ [types.StringType], xmlfile.mandatory] + t_IsA = [ [types.StringType], xmlfile.mandatory] + t_PartOf = [types.StringType, xmlfile.mandatory] + t_Archive = [Archive, xmlfile.mandatory ] + t_Patch = [ [Patch], xmlfile.mandatory, "Patches/Patch"] + t_BuildDep = [ [Dependency], xmlfile.mandatory, "BuildDependencies/Dependency"] + t_History = [ [Update], xmlfile.mandatory, "History/Update"] + + +class Package: + __metaclass__ = xmlfile.autoxml + t_Name = [ types.StringType, xmlfile.mandatory ] + t_Summary = [ types.StringType, xmlfile.mandatory ] + t_Description = [ types.StringType, xmlfile.mandatory ] + t_IsA = [ [types.StringType], xmlfile.mandatory] + t_PartOf = [types.StringType, xmlfile.mandatory] + t_History = [ [Update], xmlfile.mandatory, "History/Update"] + t_Conflicts = [ [types.StringType], xmlfile.mandatory, "Conflicts/Package"] + t_ProvidesComar = [ [ComarProvide], xmlfile.mandatory, "Provides/COMAR"] + t_RequriesComar = [ [types.StringType], xmlfile.mandatory, "Requires/COMAR"] + t_AdditionalFiles = [ [AdditionalFile], xmlfile.mandatory, "AdditionalFiles/AdditionalFile"] + diff --git a/pisi/xmlext.py b/pisi/xmlext.py index 647b769b..c6e4729e 100644 --- a/pisi/xmlext.py +++ b/pisi/xmlext.py @@ -9,17 +9,19 @@ # # Please read the COPYING file. # -# some helper functions for using minidom -# works well enough for now... :/ -# function names are mixedCase for compatibility with minidom, -# an old library - # Authors: Eray Ozkural # Baris Metin # Baris Metin + + Eray Ozkural + 868 + diff --git a/tests/xmlfiletests.py b/tests/xmlfiletests.py index db0e15bf..6f7e330c 100644 --- a/tests/xmlfiletests.py +++ b/tests/xmlfiletests.py @@ -10,19 +10,47 @@ import unittest import os +import xml.dom.minidom as mdom +from xml.parsers.expat import ExpatError +import types from pisi import xmlfile from pisi.config import config import pisi.util as util -import types +from pisi.xmlext import * class XmlFileTestCase(unittest.TestCase): def setUp(self): +# impl = mdom.getDOMImplementation() pass def testMetaClass(self): class A: __metaclass__ = xmlfile.autoxml - t_Number = [types.IntType, xmlfile.mandatory] + t_Name = [types.StringType, xmlfile.mandatory] + t_Number = [types.IntType, xmlfile.optional] + t_Email = [types.StringType, xmlfile.optional] + a_href = [types.StringType, xmlfile.mandatory] + #t_Projects = [ [types.StringType], xmlfile.mandatory] + a = A() + #print a + self.assertEqual(a.href, None) + dom = mdom.parse('tests/sandbox/a.xml') + node = getNode(dom, 'A') + self.assert_(len(A.decoders)>0) + a.decode(node) + self.assert_(a.href.startswith('http')) + self.assertEqual(a.number, 868) + self.assertEqual(a.name, 'Eray Ozkural') + string = a.format() + #print '*', string + #self.assert_(string.startswith('Name')) + outfn = '/tmp/a2.xml' + xml = xmlfile.XmlFile('A') + a2 = A() + a2.name = "Baris Metin" + a2.email = "baris@uludag.org.tr" + elt = a2.encode(xml) + string = a2.format() suite = unittest.makeSuite(XmlFileTestCase)