🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.python
Article #158

Re: gzip

#158
From: Adam Karpierz
Date: Wed, 04 Dec 2002 07:14
48 lines
2431 bytes
Użytkownik "Adam Karpierz" <karpierz@_NOSPAM_alpha.pl> napisał:

Zreszta dolacze rownie inny "przydatek":

import zipfile
import os

def unzip(archive, dstDir=None):
    if dstDir is None: dstDir = ''

    if not os.access (archive, os.R_OK):
        raise 'Cannot access %s' % archive

    if not zipfile.is_zipfile(archive):
        raise '%s: not a zipfile' % archive

    zfile = zipfile.ZipFile(archive)
    for name in zfile.namelist():
        outfile = os.path.join(dstDir, name)
        try:
            os.makedirs(os.path.dirname(outfile))
        except:
            if not os.path.isdir(os.path.dirname(outfile)):
                raise
        if os.path.basename(outfile).strip():
            if os.path.isfile(outfile):
                os.remove(outfile)
            ostream = open(outfile, "wb")
            try:
                ostream.write(zfile.read(name))
            except:
                ostream.close()
                if os.path.isfile(outfile):
                    os.remove(outfile)
                raise
            ostream.close()
        info = zfile.getinfo(name)
        date = info.date_time
        try:
            year, month, day, hour, min, sec = date
            timestamp = time.mktime((year, month, day, hour, min, sec, 0,
0, -1))
            os.utime(outfile, (timestamp, timestamp))
        except:
            pass # ignore errors

Adam Karpierz
karpierz@alpha.pl
Technical Details
Message-ID: <askadt$s4f$1@news.tpi.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!fr.clara.net!heighliner.fr.clara.net!newsfeed.tpinternet.pl!news.tpi.pl!not-for-mail
References: <ask7ug$8ko$3@news.tpi.pl> <ask9uk$p19$1@news.tpi.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!news.icm.edu.pl!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!fr.clara.net!heighliner.fr.clara.net!newsfeed.tpinternet.pl!news.tpi.pl!not-for-mail
From: "Adam Karpierz" <karpierz@_NOSPAM_alpha.pl>
Newsgroups: pl.comp.lang.python
Subject: Re: gzip
Date: Wed, 4 Dec 2002 08:14:41 +0100
Organization: tp.internet - http://www.tpi.pl/
Lines: 51
Message-ID: <askadt$s4f$1@news.tpi.pl>
References: <ask7ug$8ko$3@news.tpi.pl> <ask9uk$p19$1@news.tpi.pl>
NNTP-Posting-Host: ppp167.intertele.pl
X-Trace: news.tpi.pl 1038986494 28815 194.204.186.167 (4 Dec 2002 07:21:34 GMT)
X-Complaints-To: usenet@tpi.pl
NNTP-Posting-Date: Wed, 4 Dec 2002 07:21:34 +0000 (UTC)
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MSMail-Priority: Normal
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit