PUrl kullanmaya başladık. Aşağıdaki komutu deneyin...

./pisi-install http://cekirdek.uludag.org.tr/popt-libs-1.7-3.pisi
This commit is contained in:
Barış Metin
2005-06-28 08:56:36 +00:00
parent b57740fc03
commit f9d85f1349
4 changed files with 74 additions and 61 deletions
+2 -1
View File
@@ -71,7 +71,8 @@ class ArchiveZip(ArchiveBase):
def __init__(self, filepath, type="zip", mode='r'): def __init__(self, filepath, type="zip", mode='r'):
super(ArchiveZip, self).__init__(filepath, type) super(ArchiveZip, self).__init__(filepath, type)
self.zip = zipfile.ZipFile(filepath, mode)
self.zip = zipfile.ZipFile(self.filePath, mode)
def close(self): def close(self):
"""Close the zip archive.""" """Close the zip archive."""
+36 -26
View File
@@ -6,40 +6,50 @@
# knows what. # knows what.
# python standard library modules # python standard library modules
import urlparse
import urllib2 import urllib2
import os import os
# pisi modules # pisi modules
import util import util
from config import config from config import config
from purl import PUrl
from ui import ui
class FetchError (Exception): class FetchError (Exception):
pass pass
# helper functions
def displayProgress(pd):
out = '\r%-30.30s %3d%% %12.2f %s' % \
(pd['filename'], pd['percent'], pd['rate'], pd['symbol'])
ui.info(out)
def fetchUrl(url, dest, percentHook=None):
fetch = Fetcher(url, dest)
fetch.percentHook = percentHook
fetch.fetch()
if percentHook:
ui.info('\n')
class Fetcher: class Fetcher:
"""Fetcher can fetch a file from various sources using various """Fetcher can fetch a file from various sources using various
protocols.""" protocols."""
def __init__(self, source): def __init__(self, url, dest):
self.uri = source.archiveUri if not isinstance(url, PUrl):
self.filedest = config.archives_dir() url = PUrl(url)
self.url = url
self.filedest = dest
util.check_dir(self.filedest) util.check_dir(self.filedest)
self.scheme = "file"
self.netloc = ""
self.filepath = ""
self.filename = ""
self.percent = 0 self.percent = 0
self.rate = 0.0 self.rate = 0.0
self.percentHook = None self.percentHook = None
from string import split
u = urlparse.urlparse(self.uri)
self.scheme, self.netloc, self.filepath = u[0], u[1], u[2]
self.filename = os.path.basename(self.uri)
def fetch (self): def fetch (self):
"""Return value: Fetched file's full path..""" """Return value: Fetched file's full path.."""
if self.filename == "": if not self.url.filename():
self.err("filename error") self.err("filename error")
if os.access(self.filedest, os.W_OK) == False: if os.access(self.filedest, os.W_OK) == False:
@@ -47,13 +57,12 @@ class Fetcher:
scheme_err = lambda: self.err("unexpected scheme") scheme_err = lambda: self.err("unexpected scheme")
handlers = { if self.url.isLocalFile():
'file': self.fetchLocalFile, self.fetchLocalFile()
'http': self.fetchRemoteFile, else:
'ftp' : self.fetchRemoteFile self.fetchRemoteFile()
}; handlers.get(self.scheme, scheme_err)()
return self.filedest + "/" + self.filename return self.filedest + "/" + self.url.filename()
def doGrab(self, file, dest, totalsize): def doGrab(self, file, dest, totalsize):
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s'] symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
@@ -81,7 +90,7 @@ class Fetcher:
if p.update(size): if p.update(size):
self.percent = p.percent self.percent = p.percent
if self.percentHook != None: if self.percentHook != None:
retval = {'filename': self.filename, retval = {'filename': self.url.filename(),
'percent' : self.percent, 'percent' : self.percent,
'rate': self.rate, 'rate': self.rate,
'symbol': symbol} 'symbol': symbol}
@@ -92,13 +101,14 @@ class Fetcher:
def fetchLocalFile (self): def fetchLocalFile (self):
from shutil import copyfile from shutil import copyfile
url = self.url
if os.access(self.filepath, os.F_OK) == False: if os.access(url.path(), os.F_OK) == False:
self.err("no such file or no perm to read") self.err("no such file or no perm to read")
dest = open(self.filedest + "/" + self.filename , "w") dest = open(self.filedest + "/" + url.filename() , "w")
totalsize = os.path.getsize(self.filepath) totalsize = os.path.getsize(url.path())
file = open(self.filepath) file = open(url.path())
self.doGrab(file, dest, totalsize) self.doGrab(file, dest, totalsize)
@@ -106,7 +116,7 @@ class Fetcher:
from httplib import HTTPException from httplib import HTTPException
try: try:
file = urllib2.urlopen(self.uri) file = urllib2.urlopen(self.url.uri)
headers = file.info() headers = file.info()
except ValueError, e: except ValueError, e:
@@ -122,7 +132,7 @@ class Fetcher:
self.err('file not found') self.err('file not found')
else: totalsize = int(headers['Content-Length']) else: totalsize = int(headers['Content-Length'])
dest = open(self.filedest + "/" + self.filename , "w") dest = open(self.filedest + "/" + self.url.filename() , "w")
self.doGrab(file, dest, totalsize) self.doGrab(file, dest, totalsize)
+12 -1
View File
@@ -5,13 +5,24 @@
import archive import archive
from constants import const from constants import const
from config import config from config import config
from purl import PUrl
class Package: class Package:
"""PISI Package Class provides access to a pisi package (.pisi """PISI Package Class provides access to a pisi package (.pisi
file).""" file)."""
def __init__(self, packagefn, mode='r'): def __init__(self, packagefn, mode='r'):
self.impl = archive.ArchiveZip(packagefn, 'zip', mode)
self.filename = packagefn self.filename = packagefn
url = PUrl(packagefn)
if url.isRemoteFile():
from os import getcwd
from fetcher import fetchUrl, displayProgress
# TODO: belki Constants.packages_dir() gibi bir yere
# indirmek daha iyi olur.
fetchUrl(url, getcwd(), displayProgress)
self.filename = url.filename()
self.impl = archive.ArchiveZip(self.filename, 'zip', mode)
def add_to_package(self, fn): def add_to_package(self, fn):
"""Add a file or directory to package""" """Add a file or directory to package"""
+24 -33
View File
@@ -1,17 +1,22 @@
# -*- coding: utf-8 -*-
# python standard library # python standard library
# Authors: Baris Metin <baris@uludag.org.tr # Authors: Baris Metin <baris@uludag.org.tr
# Eray Ozkural <eray@uludag.org.tr> # Eray Ozkural <eray@uludag.org.tr>
import os from os.path import join
from os import access, R_OK
import sys import sys
# pisi modules # pisi modules
from fetcher import Fetcher
from archive import Archive from archive import Archive
import util from purl import PUrl
from ui import ui from ui import ui
from config import config
from fetcher import fetchUrl, displayProgress
import context import context
import util
class SourceArchiveError(Exception): class SourceArchiveError(Exception):
pass pass
@@ -21,36 +26,22 @@ class SourceArchive:
and unpacking a source archive""" and unpacking a source archive"""
def __init__(self, ctx): def __init__(self, ctx):
self.ctx = ctx self.ctx = ctx
self.fileName = os.path.basename(self.ctx.spec.source.archiveUri) self.url = PUrl(self.ctx.spec.source.archiveUri)
self.filePath = os.path.join(self.ctx.archives_dir(), self.fileName) self.dest = join(config.archives_dir(), self.url.filename())
def fetch(self):
if not self.isCached():
fetchUrl(self.url, config.archives_dir(), displayProgress)
def isCached(self):
if not access(self.dest, R_OK):
return False
# check hash
if util.sha1_file(self.dest) == self.ctx.spec.source.archiveSHA1:
ui.info('%s [cached]\n' % self.ctx.spec.source.archiveName)
return True
def unpack(self): def unpack(self):
archive = Archive(self.filePath, self.ctx.spec.source.archiveType) archive = Archive(self.dest, self.ctx.spec.source.archiveType)
archive.unpack(self.ctx.pkg_work_dir()) 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.spec.source)
# 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