473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CAB files

I would appreciate python code for creating *.cab files.

--V. Stokes
Aug 8 '08 #1
2 3295
Virgil Stokes schrieb:
I would appreciate python code for creating *.cab files.

--V. Stokes
Here is some code that I have still laying around. It has never been
used in production and I do not know what you can do with the cab files
it creates, but I have been able to create a cab and open it with winzip.

Thomas

<cab.py>
from ctypes import *
import sys, os, tempfile, glob

BOOL = c_int
ULONG = c_ulong
UINT = c_uint
USHORT = c_ushort

class ERF(Structure):
_fields_ = [("erfOper", c_int),
("erfType", c_int),
("fError", BOOL)]

CB_MAX_CHUNK = 32768
CB_MAX_DISK = 0x7ffffff
CB_MAX_FILENAME = 256
CB_MAX_CABINET_NAME = 256
CB_MAX_CAB_PATH = 256
CB_MAX_DISK_NAME = 256

class CCAB(Structure):
_fields_ = [
("cb", ULONG), # size available for cabinet on this media
("cbFolderThresh", ULONG), # Thresshold for forcing a new Folder
("cbReserveCFHeader", UINT), # Space to reserve in CFHEADER
("cbReserveCFFolder", UINT), # Space to reserve in CFFOLDER
("cbReserveCFData", UINT), # Space to reserve in CFDATA
("iCab", c_int), # sequential numbers for cabinets
("iDisk", c_int), # Disk number
("fFailOnIncompressible", c_int), # TRUE =Fail if a block is incompressible
("setID", USHORT), # Cabinet set ID
("szDisk", c_char * CB_MAX_DISK_NAME), # current disk name
("szCab", c_char * CB_MAX_CABINET_NAME), # current cabinet name
("szCabPath", c_char * CB_MAX_CAB_PATH), # path for creating cabinet
]

cab = cdll.cabinet

class HFCI(object):
_handle = 0
_as_parameter_ = property(lambda self: self._handle)

def __init__(self, fnm, verbose=1):
self.verbose = verbose
self.erf = ERF()
ccab = self.ccab = CCAB()
ccab.cb = 100000000
ccab.cbFolderThresh = 100000
ccab.szCab = os.path.basename(fnm)
dirname = os.path.dirname(fnm)
if not dirname:
dirname = "."
ccab.szCabPath = dirname + "\\"
self._init_callbacks()
self._handle = cab.FCICreate(byref(self.erf),
self.pfn_filedest,
cdll.msvcrt.malloc,
cdll.msvcrt.free,
cdll.msvcrt._open,
cdll.msvcrt._read,
cdll.msvcrt._write,
cdll.msvcrt._close,
cdll.msvcrt._lseek,
cdll.msvcrt._unlink,
self.pfn_gettempfnm,
byref(ccab),
None)

def _init_callbacks(self):
self.pfn_gettempfnm = CFUNCTYPE(c_int, c_void_p, c_int, c_void_p)(self._gettempfnm)
self.pfn_filedest = CFUNCTYPE(c_int)(self._filedest)
self.pfn_status = CFUNCTYPE(c_int, c_int, c_uint, c_uint, c_void_p)(self._status)
self.pfn_getnextcab = CFUNCTYPE(c_int)(self._getnextcab)
self.pfn_getopeninfo = CFUNCTYPE(c_int, c_char_p)(self._getopeninfo)

def _getopeninfo(self, fnm):
if self.verbose:
print "File", fnm
return cdll.msvcrt._open(fnm, os.O_BINARY | os.O_RDONLY)

def _status(self, typeStatus, cb1, cb2, pv):
return 0

def _filedest(self):
return 0

def _getnextcab(self):
return 0

def _gettempfnm(self, pszTempName, cbTempName, pv):
# same as tempfile.mktemp(), but this is deprecated
fh, fnm = tempfile.mkstemp()
os.close(fh)
os.remove(fnm)
cdll.msvcrt.strcpy(pszTempName, fnm)
return 1

def AddFile(self, src, dst=None, compressed=0):
if dst is None:
dst = os.path.basename(src)
cab.FCIAddFile(self,
src,
dst,
0, # fExecute
self.pfn_getnextcab,
self.pfn_status,
self.pfn_getopeninfo,
compressed)

def Close(self):
if self._handle != 0:
cab.FCIFlushCabinet(self,
0, # fGetNextCab
self.pfn_getnextcab,
self.pfn_status)
cab.FCIDestroy(self)
self._handle = 0

if __name__ == "__main__":
import os, glob

hfci = HFCI("my-first.cab", verbose=1)

files = glob.glob(r".\cab\*.*")

for fnm in files:
hfci.AddFile(fnm)

hfci.Close()
<eof>
Aug 8 '08 #2
I would appreciate python code for creating *.cab files.

The msilib module of Python 2.5 can be used to create CAB files,
through msilib.FCICreate(cabname, filelist), where filelist is
a list of (systempath, cabpath).

Regards,
Martin
Aug 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
44
by: Xah Lee | last post by:
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical, but you don't know which ones are...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
18
by: JKop | last post by:
Here's what I know so far: You have a C++ project. You have source files in it. When you go to compile it, first thing the preprocessor sticks the header files into each source file. So now...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
11
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how...
22
by: Daniel Billingsley | last post by:
Ok, I wanted to ask this separate from nospam's ridiculous thread in hopes it could get some honest attention. VB6 had a some simple and fast mechanisms for retrieving values from basic text...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
0
by: wal | last post by:
How does one attach files to emails using libgmail? The following code http://pramode.net/articles/lfy/fuse/4.txt works fine when said files are simple text files, but it failes as soon as the...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.