zipfs.py :  » Web-Server » SkunkWEB » skunkweb-3.4.4 » pylibs » vfs » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Server » SkunkWEB 
SkunkWEB » skunkweb 3.4.4 » pylibs » vfs » zipfs.py
# $Id$
# Time-stamp: <03/08/11 13:12:17 smulloni>

######################################################################## 
#  Copyright (C) 2001 Jocob Smullyan <smulloni@smullyan.org>
#  
#      You may distribute under the terms of either the GNU General
#      Public License or the SkunkWeb License, as specified in the
#      README file.
########################################################################

import zipfile
from vfs import FS,VFSException,FileNotFoundException,NotWriteableException
from rosio import RO_StringIO
import time
import os
import pathutil

class ZipFS(FS):

    writeable=0
    
    def __init__(self, zippath, root='', prefix='/'):
        if not zipfile.is_zipfile(zippath):
            raise zipfile.BadZipfile, "not a zip file: %s" % zippath
        self.zpath=os.path.abspath(zippath)
        self.__zfile=zipfile.ZipFile(zippath, mode='r')
        self.__archive=pathutil.Archive(root, prefix)
        self.prefix=prefix
        self.root=root
        self.__archive.savePaths(self.__zfile.namelist())

    def ministat(self, path):
        adjusted=pathutil._adjust_user_path(path)
        if not self.__archive.paths.has_key(adjusted): 
            raise FileNotFoundException, path
        realname=self.__archive.paths[adjusted]
        if realname==None:
            arcstat=os.stat(self.zpath)[7:]
            return (0,) + arcstat
        info=self.__zfile.getinfo(realname)
        modtime=int(time.mktime(info.date_time + (0, 0, 0)))
        return info.file_size, -1, modtime, modtime

    def open(self, path, mode='r'):
        adjusted=pathutil._adjust_user_path(path)
        if mode!='r':
            raise NotWriteableException, "unsupported file open mode: %s" % mode
        if not self.__archive.paths.has_key(adjusted):
            raise FileNotFoundException, path
        realname=self.__archive.paths[adjusted]
        if realname!=None:
            return RO_StringIO(adjusted,
                               self.__zfile.read(realname))
        else:
            raise VFSException, "cannot open directory as file: %s" % path

    def listdir(self, path):
        return self.__archive.listdir(path)
        
    def exists(self, path):
        return self.__archive.exists(path)

    def isdir(self, path):
        adjusted=pathutil._adjust_user_path(path)
        if not self.__archive.paths.has_key(adjusted):
            #raise FileNotFoundException, path
            return 0
        realname=self.__archive.paths[adjusted]
        if realname==None:
            return 1
        else:
            # on UNIX, I'd hope to get this from file attributes;
            # Per Boethner's implementation of java.util.zip.ZipEntry
            # for GNU Classpath only tests the final slash
            return realname.endswith('/') and \
                   self.__zfile.getinfo(realname).file_size==0

    def isfile(self, path):
        adjusted=pathutil._adjust_user_path(path)
        if not self.__archive.paths.has_key(adjusted):
            #raise FileNotFoundException, path
            return 0
        realname=self.__archive.paths[adjusted]
        if realname==None:
            return 0
        else:
            return not adjusted.endswith('/')


########################################################################
# $Log$
# Revision 1.9  2003/08/11 17:15:32  smulloni
# replacing "<>" with "!=".  (Makes Brian Olsen happy.)
#
# Revision 1.8  2003/05/01 20:46:02  drew_csillag
# Changed license text
#
# Revision 1.7  2002/02/21 07:20:17  smulloni
# numerous changes for product service and vfs, to support importing from the
# latter.
#
# Revision 1.6  2002/02/20 04:54:14  smulloni
# vfs fixes and first cut at a product service.
#
# Revision 1.5  2002/02/19 17:17:49  smulloni
# vfs improvements; documentation typo fix.
#
# Revision 1.4  2002/01/10 02:34:18  smulloni
# vfs tweaks
#
# Revision 1.3  2002/01/02 06:39:24  smulloni
# work on vfs
#
# Revision 1.2  2001/12/02 20:57:50  smulloni
# First fold of work done in September (!) on dev3_2 branch into trunk:
# vfs and PyDO enhancements (webdav still to come).  Also, small enhancement
# to templating's <:img:> tag.
#
# Revision 1.1.2.1  2001/09/27 03:36:07  smulloni
# new pylibs, work on PyDO, code cleanup.
#
########################################################################

    

    

    


            
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.