* minor refactoring, add a util module
* add write support to specfile * remove caching from specfile sayin arkadaslarim burada write icin koydugum seyleri silmeyin bu tam olmamis duzeltiyorum, o getlere de genel olarak ihtiyac yok. *client* icin nasil kolay oluyorsa oyle olmali yanlis su: bir class icindeki state'i cache etmez store eder cache etmek ne zaman gerekir? represent ettigi data core'a sigmiyorsa. diger zamanlarda yanlis bir metod olur. otesinde de refactor ediyorum biraz -- eray
This commit is contained in:
+6
-2
@@ -1,6 +1,7 @@
|
|||||||
#import package
|
#import package
|
||||||
from specfile import SpecFile
|
from specfile import SpecFile
|
||||||
from package import Package
|
from package import Package
|
||||||
|
import util
|
||||||
#import repodb
|
#import repodb
|
||||||
#import packagedb
|
#import packagedb
|
||||||
#import dependency
|
#import dependency
|
||||||
@@ -11,10 +12,13 @@ def install_package_file(package_fn):
|
|||||||
|
|
||||||
package = Package(package_fn, "r")
|
package = Package(package_fn, "r")
|
||||||
# extract control files
|
# extract control files
|
||||||
package.extract_files(tmp_dir + "install/")
|
util.clean_directory(install_dir)
|
||||||
|
package.extract_files(install_dir)
|
||||||
|
|
||||||
# verify package
|
# verify package
|
||||||
# check file semantics
|
# check pspec semantics
|
||||||
|
|
||||||
|
|
||||||
# check file system requirements
|
# check file system requirements
|
||||||
# check conflicts
|
# check conflicts
|
||||||
# check dependencies
|
# check dependencies
|
||||||
|
|||||||
+5
-35
@@ -10,38 +10,8 @@ from fetcher import Fetcher
|
|||||||
# import pisipackage
|
# import pisipackage
|
||||||
# import pisiutils # patch, fileutils?
|
# import pisiutils # patch, fileutils?
|
||||||
import pisiconfig
|
import pisiconfig
|
||||||
|
import util
|
||||||
class PisiBuildError(Exception):
|
from pisibuild import PisiBuild
|
||||||
pass
|
|
||||||
|
|
||||||
class PisiBuild:
|
|
||||||
"""PisiBuild class, provides the package build and creation rutines"""
|
|
||||||
def __init__(self, pspecfile):
|
|
||||||
self.pspecfile = pspecfile
|
|
||||||
pspec = SpecFile(pspecfile)
|
|
||||||
|
|
||||||
self.packageName = pspec.getSourceName()
|
|
||||||
|
|
||||||
self.archiveUri = pspec.getArchiveUri()
|
|
||||||
self.archiveName = basename(self.archiveUri)
|
|
||||||
self.archiveType = pspec.getArchiveType()
|
|
||||||
self.archiveHash = pspec.getArchiveHash()
|
|
||||||
|
|
||||||
self.pspec = pspec
|
|
||||||
|
|
||||||
def fetchArchive(self):
|
|
||||||
fetch = Fetcher(self.archiveUri)
|
|
||||||
fetch.fetch()
|
|
||||||
|
|
||||||
|
|
||||||
def information(message):
|
|
||||||
print message
|
|
||||||
|
|
||||||
def usage(progname = "pisi-build"):
|
|
||||||
print """
|
|
||||||
Usage:
|
|
||||||
%s [options] package-name.pspec
|
|
||||||
""" %(progname)
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sys
|
import sys
|
||||||
@@ -77,11 +47,11 @@ def main():
|
|||||||
|
|
||||||
# doing the real job... vs. vs...
|
# doing the real job... vs. vs...
|
||||||
pb = PisiBuild(pspec)
|
pb = PisiBuild(pspec)
|
||||||
information("Building PISI package for: %s" % pb.packageName)
|
util.information("Building PISI package for: %s" % pb.packageName)
|
||||||
information("Fetching source from: %s (be patient)" % pb.archiveUri)
|
util.information("Fetching source from: %s (be patient)" % pb.archiveUri)
|
||||||
print pb.archiveType, pb.archiveHash
|
print pb.archiveType, pb.archiveHash
|
||||||
pb.fetchArchive()
|
pb.fetchArchive()
|
||||||
information("Source archive is stored: %s/%s" %(pisiconfig.archives_dir, pb.archiveName))
|
util.information("Source archive is stored: %s/%s" %(pisiconfig.archives_dir, pb.archiveName))
|
||||||
# pb.unpackArchive()
|
# pb.unpackArchive()
|
||||||
# pb.applyPatches()
|
# pb.applyPatches()
|
||||||
# pb.buildSource()
|
# pb.buildSource()
|
||||||
|
|||||||
+28
-85
@@ -1,99 +1,42 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
|
from xmlfile import XmlFile
|
||||||
|
|
||||||
class Patch:
|
class PatchInfo:
|
||||||
def __init__(self, filename, patchtype):
|
def __init__(self, filenm, ctype):
|
||||||
self.filename = filename
|
self.filename = filenm
|
||||||
self.compressionType = patchtype
|
self.compressionType = ctype
|
||||||
|
|
||||||
class XmlFile(object):
|
|
||||||
"""A class for retrieving information from an XML file"""
|
|
||||||
|
|
||||||
def __init__(self, specfile):
|
|
||||||
self.dom = xml.dom.minidom.parse(specfile)
|
|
||||||
|
|
||||||
def getNodes(self, nodepath):
|
|
||||||
"""getNodes function return nodes for given path of the node.
|
|
||||||
|
|
||||||
getNodes("PSPEC/Source/Name")
|
|
||||||
returns an array of Name nodes in PSPEC/Source"""
|
|
||||||
|
|
||||||
nodeArray=nodepath.split('/')
|
|
||||||
|
|
||||||
# get DOM for top node
|
|
||||||
nodelist = self.dom.getElementsByTagName(nodeArray[0])
|
|
||||||
# iterate over
|
|
||||||
for nodename in nodeArray[1:]:
|
|
||||||
nodelist = nodelist[0].getElementsByTagName(nodename)
|
|
||||||
|
|
||||||
return nodelist
|
|
||||||
|
|
||||||
def getFirstNode(self, nodepath):
|
|
||||||
try:
|
|
||||||
return self.getNodes(nodepath)[0]
|
|
||||||
except IndexError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def getNodeText(self, node):
|
|
||||||
# get the first child
|
|
||||||
try:
|
|
||||||
child = node.childNodes[0]
|
|
||||||
except IndexError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if child.nodeType == child.TEXT_NODE:
|
|
||||||
return child.data
|
|
||||||
|
|
||||||
def getFirstChildText(self, nodepath):
|
|
||||||
node = self.getFirstNode(nodepath)
|
|
||||||
if not node:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return self.getNodeText(node)
|
|
||||||
|
|
||||||
def getNodeAttribute(self, node, attrname):
|
|
||||||
for i in range(node.attributes.length):
|
|
||||||
attr = node.attributes.item(i)
|
|
||||||
if attr.name == attrname:
|
|
||||||
return attr.childNodes[0].data
|
|
||||||
|
|
||||||
|
# sayin arkadaslarim burada write icin koydugum seyleri silmeyin
|
||||||
|
# bu tam olmamis duzeltiyorum, o getlere de genel olarak
|
||||||
|
# ihtiyac yok. *client* icin nasil kolay oluyorsa oyle olmali
|
||||||
|
# yanlis su: bir class icindeki state'i cache etmez store eder
|
||||||
|
# cache etmek ne zaman gerekir? represent ettigi data core'a
|
||||||
|
# sigmiyorsa. diger zamanlarda yanlis bir metod olur.
|
||||||
|
# otesinde de refactor ediyorum biraz -- eray
|
||||||
|
|
||||||
class SpecFile(XmlFile):
|
class SpecFile(XmlFile):
|
||||||
"""A class for retrieving specific information from a
|
"""A class for reading/writing from/to a PSPEC (PISI SPEC) file."""
|
||||||
PSPEC (PISI SPEC) file.
|
|
||||||
|
|
||||||
Information retrieved from PSPEC file is cached (where possible)
|
|
||||||
once accessed, for further usage.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, specfile):
|
|
||||||
super(SpecFile, self).__init__(specfile)
|
|
||||||
|
|
||||||
|
def read(self, filename):
|
||||||
|
"""Read PSPEC file"""
|
||||||
|
self.readxml(filename)
|
||||||
self.archiveNode = self.getFirstNode("PSPEC/Source/Archive")
|
self.archiveNode = self.getFirstNode("PSPEC/Source/Archive")
|
||||||
|
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
|
||||||
|
self.archiveUri = self.getNodeText(self.archiveNode).strip()
|
||||||
|
self.archiveType = self.getNodeAttribute(self.archiveNode, "archType")
|
||||||
|
self.archiveHash = self.getNodeAttribute(self.archiveNode, "md5sum")
|
||||||
|
|
||||||
def getSourceName(self):
|
def verify(self):
|
||||||
try:
|
"""Verify PSPEC structures, are they what we want of them?"""
|
||||||
return self.sourceName
|
return True
|
||||||
except AttributeError:
|
|
||||||
print "buraya yalnızca bir defa gelebilirsin..."
|
def write(self, filename):
|
||||||
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
|
"""Write PSPEC file"""
|
||||||
return self.sourceName
|
self.writexml(filename)
|
||||||
|
|
||||||
def getArchiveUri(self):
|
|
||||||
try:
|
|
||||||
return self.archiveUri
|
|
||||||
except AttributeError:
|
|
||||||
self.archiveUri = self.getNodeText(self.archiveNode).strip()
|
|
||||||
return self.archiveUri
|
|
||||||
|
|
||||||
def getArchiveType(self):
|
|
||||||
return self.getNodeAttribute(self.archiveNode, "archType")
|
|
||||||
|
|
||||||
def getArchiveHash(self):
|
|
||||||
return self.getNodeAttribute(self.archiveNode, "md5sum")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
sys.stderr.write("Not a callable module!")
|
sys.stderr.write("Not a callable module!")
|
||||||
|
exit(-1)
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import xml.dom.minidom
|
||||||
|
|
||||||
|
class XmlFile(object):
|
||||||
|
"""A class for retrieving information from an XML file"""
|
||||||
|
|
||||||
|
def readxml(self, filenm):
|
||||||
|
self.dom = xml.dom.minidom.parse(filenm)
|
||||||
|
|
||||||
|
def writexml(self, filenm):
|
||||||
|
f = file(filenm,'w')
|
||||||
|
dom.writetoxml(f)
|
||||||
|
|
||||||
|
def getNodes(self, nodepath):
|
||||||
|
"""getNodes function return nodes for given path of the node.
|
||||||
|
|
||||||
|
getNodes("PSPEC/Source/Name")
|
||||||
|
returns an array of Name nodes in PSPEC/Source"""
|
||||||
|
|
||||||
|
nodeArray=nodepath.split('/')
|
||||||
|
|
||||||
|
# get DOM for top node
|
||||||
|
nodelist = self.dom.getElementsByTagName(nodeArray[0])
|
||||||
|
# iterate over
|
||||||
|
for nodename in nodeArray[1:]:
|
||||||
|
nodelist = nodelist[0].getElementsByTagName(nodename)
|
||||||
|
|
||||||
|
return nodelist
|
||||||
|
|
||||||
|
def getFirstNode(self, nodepath):
|
||||||
|
try:
|
||||||
|
return self.getNodes(nodepath)[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getNodeText(self, node):
|
||||||
|
# get the first child
|
||||||
|
try:
|
||||||
|
child = node.childNodes[0]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
if child.nodeType == child.TEXT_NODE:
|
||||||
|
return child.data
|
||||||
|
|
||||||
|
def getFirstChildText(self, nodepath):
|
||||||
|
node = self.getFirstNode(nodepath)
|
||||||
|
if not node:
|
||||||
|
return None
|
||||||
|
|
||||||
|
return self.getNodeText(node)
|
||||||
|
|
||||||
|
def getNodeAttribute(self, node, attrname):
|
||||||
|
for i in range(node.attributes.length):
|
||||||
|
attr = node.attributes.item(i)
|
||||||
|
if attr.name == attrname:
|
||||||
|
return attr.childNodes[0].data
|
||||||
Reference in New Issue
Block a user