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:
+2
-1
@@ -71,7 +71,8 @@ class ArchiveZip(ArchiveBase):
|
||||
|
||||
def __init__(self, filepath, type="zip", mode='r'):
|
||||
super(ArchiveZip, self).__init__(filepath, type)
|
||||
self.zip = zipfile.ZipFile(filepath, mode)
|
||||
|
||||
self.zip = zipfile.ZipFile(self.filePath, mode)
|
||||
|
||||
def close(self):
|
||||
"""Close the zip archive."""
|
||||
|
||||
+36
-26
@@ -6,40 +6,50 @@
|
||||
# knows what.
|
||||
|
||||
# python standard library modules
|
||||
import urlparse
|
||||
import urllib2
|
||||
import os
|
||||
|
||||
# pisi modules
|
||||
import util
|
||||
from config import config
|
||||
from purl import PUrl
|
||||
from ui import ui
|
||||
|
||||
class FetchError (Exception):
|
||||
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:
|
||||
"""Fetcher can fetch a file from various sources using various
|
||||
protocols."""
|
||||
def __init__(self, source):
|
||||
self.uri = source.archiveUri
|
||||
self.filedest = config.archives_dir()
|
||||
def __init__(self, url, dest):
|
||||
if not isinstance(url, PUrl):
|
||||
url = PUrl(url)
|
||||
|
||||
self.url = url
|
||||
self.filedest = dest
|
||||
util.check_dir(self.filedest)
|
||||
self.scheme = "file"
|
||||
self.netloc = ""
|
||||
self.filepath = ""
|
||||
self.filename = ""
|
||||
self.percent = 0
|
||||
self.rate = 0.0
|
||||
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):
|
||||
"""Return value: Fetched file's full path.."""
|
||||
|
||||
if self.filename == "":
|
||||
if not self.url.filename():
|
||||
self.err("filename error")
|
||||
|
||||
if os.access(self.filedest, os.W_OK) == False:
|
||||
@@ -47,13 +57,12 @@ class Fetcher:
|
||||
|
||||
scheme_err = lambda: self.err("unexpected scheme")
|
||||
|
||||
handlers = {
|
||||
'file': self.fetchLocalFile,
|
||||
'http': self.fetchRemoteFile,
|
||||
'ftp' : self.fetchRemoteFile
|
||||
}; handlers.get(self.scheme, scheme_err)()
|
||||
if self.url.isLocalFile():
|
||||
self.fetchLocalFile()
|
||||
else:
|
||||
self.fetchRemoteFile()
|
||||
|
||||
return self.filedest + "/" + self.filename
|
||||
return self.filedest + "/" + self.url.filename()
|
||||
|
||||
def doGrab(self, file, dest, totalsize):
|
||||
symbols = [' B/s', 'KB/s', 'MB/s', 'GB/s']
|
||||
@@ -81,7 +90,7 @@ class Fetcher:
|
||||
if p.update(size):
|
||||
self.percent = p.percent
|
||||
if self.percentHook != None:
|
||||
retval = {'filename': self.filename,
|
||||
retval = {'filename': self.url.filename(),
|
||||
'percent' : self.percent,
|
||||
'rate': self.rate,
|
||||
'symbol': symbol}
|
||||
@@ -92,13 +101,14 @@ class Fetcher:
|
||||
|
||||
def fetchLocalFile (self):
|
||||
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")
|
||||
|
||||
dest = open(self.filedest + "/" + self.filename , "w")
|
||||
totalsize = os.path.getsize(self.filepath)
|
||||
file = open(self.filepath)
|
||||
dest = open(self.filedest + "/" + url.filename() , "w")
|
||||
totalsize = os.path.getsize(url.path())
|
||||
file = open(url.path())
|
||||
self.doGrab(file, dest, totalsize)
|
||||
|
||||
|
||||
@@ -106,7 +116,7 @@ class Fetcher:
|
||||
from httplib import HTTPException
|
||||
|
||||
try:
|
||||
file = urllib2.urlopen(self.uri)
|
||||
file = urllib2.urlopen(self.url.uri)
|
||||
headers = file.info()
|
||||
|
||||
except ValueError, e:
|
||||
@@ -122,7 +132,7 @@ class Fetcher:
|
||||
self.err('file not found')
|
||||
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)
|
||||
|
||||
|
||||
|
||||
+12
-1
@@ -5,13 +5,24 @@
|
||||
import archive
|
||||
from constants import const
|
||||
from config import config
|
||||
from purl import PUrl
|
||||
|
||||
class Package:
|
||||
"""PISI Package Class provides access to a pisi package (.pisi
|
||||
file)."""
|
||||
def __init__(self, packagefn, mode='r'):
|
||||
self.impl = archive.ArchiveZip(packagefn, 'zip', mode)
|
||||
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):
|
||||
"""Add a file or directory to package"""
|
||||
|
||||
+24
-33
@@ -1,17 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# python standard library
|
||||
# Authors: Baris Metin <baris@uludag.org.tr
|
||||
# Eray Ozkural <eray@uludag.org.tr>
|
||||
|
||||
import os
|
||||
from os.path import join
|
||||
from os import access, R_OK
|
||||
import sys
|
||||
|
||||
|
||||
# pisi modules
|
||||
from fetcher import Fetcher
|
||||
from archive import Archive
|
||||
import util
|
||||
from purl import PUrl
|
||||
from ui import ui
|
||||
from config import config
|
||||
from fetcher import fetchUrl, displayProgress
|
||||
import context
|
||||
import util
|
||||
|
||||
|
||||
class SourceArchiveError(Exception):
|
||||
pass
|
||||
@@ -21,36 +26,22 @@ class SourceArchive:
|
||||
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)
|
||||
self.url = PUrl(self.ctx.spec.source.archiveUri)
|
||||
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):
|
||||
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())
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user