* 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
|
||||
from specfile import SpecFile
|
||||
from package import Package
|
||||
import util
|
||||
#import repodb
|
||||
#import packagedb
|
||||
#import dependency
|
||||
@@ -11,10 +12,13 @@ def install_package_file(package_fn):
|
||||
|
||||
package = Package(package_fn, "r")
|
||||
# extract control files
|
||||
package.extract_files(tmp_dir + "install/")
|
||||
util.clean_directory(install_dir)
|
||||
package.extract_files(install_dir)
|
||||
|
||||
# verify package
|
||||
# check file semantics
|
||||
# check pspec semantics
|
||||
|
||||
|
||||
# check file system requirements
|
||||
# check conflicts
|
||||
# check dependencies
|
||||
|
||||
+5
-35
@@ -10,38 +10,8 @@ from fetcher import Fetcher
|
||||
# import pisipackage
|
||||
# import pisiutils # patch, fileutils?
|
||||
import pisiconfig
|
||||
|
||||
class PisiBuildError(Exception):
|
||||
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)
|
||||
import util
|
||||
from pisibuild import PisiBuild
|
||||
|
||||
def main():
|
||||
import sys
|
||||
@@ -77,11 +47,11 @@ def main():
|
||||
|
||||
# doing the real job... vs. vs...
|
||||
pb = PisiBuild(pspec)
|
||||
information("Building PISI package for: %s" % pb.packageName)
|
||||
information("Fetching source from: %s (be patient)" % pb.archiveUri)
|
||||
util.information("Building PISI package for: %s" % pb.packageName)
|
||||
util.information("Fetching source from: %s (be patient)" % pb.archiveUri)
|
||||
print pb.archiveType, pb.archiveHash
|
||||
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.applyPatches()
|
||||
# pb.buildSource()
|
||||
|
||||
+28
-85
@@ -1,99 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import xml.dom.minidom
|
||||
from xmlfile import XmlFile
|
||||
|
||||
class Patch:
|
||||
def __init__(self, filename, patchtype):
|
||||
self.filename = filename
|
||||
self.compressionType = patchtype
|
||||
|
||||
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
|
||||
class PatchInfo:
|
||||
def __init__(self, filenm, ctype):
|
||||
self.filename = filenm
|
||||
self.compressionType = ctype
|
||||
|
||||
# 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):
|
||||
"""A class for retrieving specific information from a
|
||||
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)
|
||||
"""A class for reading/writing from/to a PSPEC (PISI SPEC) file."""
|
||||
|
||||
def read(self, filename):
|
||||
"""Read PSPEC file"""
|
||||
self.readxml(filename)
|
||||
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):
|
||||
try:
|
||||
return self.sourceName
|
||||
except AttributeError:
|
||||
print "buraya yalnızca bir defa gelebilirsin..."
|
||||
self.sourceName = self.getFirstChildText("PSPEC/Source/Name")
|
||||
return self.sourceName
|
||||
|
||||
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")
|
||||
|
||||
def verify(self):
|
||||
"""Verify PSPEC structures, are they what we want of them?"""
|
||||
return True
|
||||
|
||||
def write(self, filename):
|
||||
"""Write PSPEC file"""
|
||||
self.writexml(filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
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