* refactoring zamani:
- sourcearchive tam olarak baris'in dediklerini ve biraz daha fazlasini
yapan akilli bir class'tir. bir tanedir. sirinlikten yanina varilmaz. :)
This commit is contained in:
+6
-45
@@ -6,49 +6,37 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from fetcher import Fetcher
|
|
||||||
from archive import Archive
|
|
||||||
|
|
||||||
# import pisipackage
|
# import pisipackage
|
||||||
import util
|
import util
|
||||||
from ui import ui
|
from ui import ui
|
||||||
|
from context import ctx
|
||||||
|
from sourcearchive import SourceArchive
|
||||||
|
|
||||||
class PisiBuildError(Exception):
|
class PisiBuildError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# FIXME: this eventually has to go to ui module
|
|
||||||
# Infact all ui calls has nothing to do with this build process.
|
|
||||||
# There more of them in PisiBuild...
|
|
||||||
# And maybe we should consider moving PisiBuild.build() back to pisi-build
|
|
||||||
# CLI too.
|
|
||||||
# exa: This, like all others, will have a GUI or CLI, interchangeably
|
|
||||||
def displayProgress(pd):
|
|
||||||
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
|
||||||
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
|
||||||
ui.info(out)
|
|
||||||
|
|
||||||
class PisiBuild:
|
class PisiBuild:
|
||||||
"""PisiBuild class, provides the package build and creation routines"""
|
"""PisiBuild class, provides the package build and creation routines"""
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.ctx = context
|
self.ctx = context
|
||||||
self.work_dir = self.ctx.pkg_work_dir()
|
self.work_dir = self.ctx.pkg_work_dir()
|
||||||
|
|
||||||
self.spec = self.ctx.spec
|
self.spec = self.ctx.spec
|
||||||
|
self.sourceArchive = SourceArchive(self.ctx)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
ui.info("Building PISI source package: %s\n" % self.spec.source.name)
|
||||||
|
|
||||||
ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri)
|
ui.info("Fetching source from: %s\n" % self.spec.source.archiveUri)
|
||||||
self.fetchArchive(displayProgress)
|
self.sourceArchive.fetch()
|
||||||
ui.info("Source archive is stored: %s/%s\n"
|
ui.info("Source archive is stored: %s/%s\n"
|
||||||
%(self.ctx.archives_dir(), self.spec.source.archiveName))
|
%(self.ctx.archives_dir(), self.spec.source.archiveName))
|
||||||
|
|
||||||
self.solveBuildDependencies()
|
self.solveBuildDependencies()
|
||||||
|
|
||||||
ui.info("Unpacking archive...")
|
ui.info("Unpacking archive...")
|
||||||
self.unpackArchive()
|
self.sourceArchive.unpack()
|
||||||
ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir())
|
ui.info(" unpacked (%s)\n" % self.ctx.pkg_work_dir())
|
||||||
|
|
||||||
self.applyPatches()
|
self.applyPatches()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -83,36 +71,9 @@ class PisiBuild:
|
|||||||
# after all, we are ready to build/prepare the packages
|
# after all, we are ready to build/prepare the packages
|
||||||
self.buildPackages()
|
self.buildPackages()
|
||||||
|
|
||||||
def fetchArchive(self, percentHook=None):
|
|
||||||
"""fetch an archive and store to ctx.archives_dir()
|
|
||||||
using fether.Fetcher"""
|
|
||||||
fetch = Fetcher(self.ctx)
|
|
||||||
|
|
||||||
# check if source already cached
|
|
||||||
destpath = fetch.filedest + "/" + fetch.filename
|
|
||||||
if os.access(destpath, os.R_OK):
|
|
||||||
if util.sha1_file(destpath) == self.spec.source.archiveSHA1:
|
|
||||||
ui.info('%s [cached]\n' % self.spec.source.archiveName)
|
|
||||||
return
|
|
||||||
|
|
||||||
if percentHook:
|
|
||||||
fetch.percentHook = percentHook
|
|
||||||
|
|
||||||
fetch.fetch()
|
|
||||||
|
|
||||||
# FIXME: What a ugly hack! We should really find a cleaner way for output.
|
|
||||||
if percentHook:
|
|
||||||
ui.info('\n')
|
|
||||||
|
|
||||||
def solveBuildDependencies(self):
|
def solveBuildDependencies(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def unpackArchive(self):
|
|
||||||
fileName = os.path.basename(self.ctx.spec.source.archiveUri)
|
|
||||||
filePath = self.ctx.archives_dir() + '/' + fileName
|
|
||||||
archive = Archive(filePath, self.ctx.spec.source.archiveType)
|
|
||||||
archive.unpack(self.work_dir)
|
|
||||||
|
|
||||||
def applyPatches(self):
|
def applyPatches(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
# python standard library
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
# pisi modules
|
||||||
|
from fetcher import Fetcher
|
||||||
|
from archive import Archive
|
||||||
|
import util
|
||||||
|
from ui import ui
|
||||||
|
import context
|
||||||
|
from context import ctx
|
||||||
|
|
||||||
|
class SourceArchiveError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class SourceArchive:
|
||||||
|
"""source archive. this is a class responsible for fetching
|
||||||
|
and unpacking a source archive"""
|
||||||
|
def __init__(self, ctx):
|
||||||
|
self.ctx = ctx
|
||||||
|
self.fileName = os.path.basename(self.ctx.spec.source.archiveUri)
|
||||||
|
self.filePath = os.path.join(self.ctx.archives_dir(), self.fileName)
|
||||||
|
|
||||||
|
def unpack(self):
|
||||||
|
archive = Archive(self.filePath, self.ctx.spec.source.archiveType)
|
||||||
|
archive.unpack(self.ctx.pkg_work_dir())
|
||||||
|
|
||||||
|
def displayProgress(pd):
|
||||||
|
out = '\r%-30.30s %3d%% %12.2f %s' % \
|
||||||
|
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
|
||||||
|
ui.info(out)
|
||||||
|
|
||||||
|
def fetch(self, percentHook=displayProgress):
|
||||||
|
"""fetch an archive and store to ctx.archives_dir()
|
||||||
|
using fetcher.Fetcher"""
|
||||||
|
fetch = Fetcher(self.ctx)
|
||||||
|
|
||||||
|
# check if source already cached
|
||||||
|
destpath = fetch.filedest + "/" + fetch.filename
|
||||||
|
if os.access(destpath, os.R_OK):
|
||||||
|
if util.sha1_file(destpath) == self.ctx.spec.source.archiveSHA1:
|
||||||
|
ui.info('%s [cached]\n' % self.ctx.spec.source.archiveName)
|
||||||
|
return
|
||||||
|
|
||||||
|
if percentHook:
|
||||||
|
fetch.percentHook = percentHook
|
||||||
|
|
||||||
|
fetch.fetch()
|
||||||
|
|
||||||
|
# FIXME: What a ugly hack! We should really find a cleaner way for output.
|
||||||
|
if percentHook:
|
||||||
|
ui.info('\n')
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user