[go: up one dir, main page]

Menu

[r36]: / package.py  Maximize  Restore  History

Download this file

65 lines (55 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# ooolib-python Packager
# We are going to package the version of ooolib-python found in the
# ooolib-python/ directory.
import sys, os, commands
sys.path.insert(0, 'ooolib-python')
import ooolib
# Get the version number for directory creation
newdir = ooolib.version()
def createdir(dir):
if os.path.isdir(dir):
print " Exists: %s/" % dir
return
else:
os.makedirs(dir)
print " Created: %s/" % dir
def copyfiles(sdir, tdir, ext=''):
files = os.listdir(sdir)
files.sort()
for file in files:
sourcefile = os.path.join(sdir, file)
targetfile = os.path.join(tdir, file)
# Skip non-files
if not os.path.isfile(sourcefile): continue
# determine the extension
root, sourceext = os.path.splitext(sourcefile)
if ext and sourceext != ext: continue
# Make sure the target does not exist
if (os.path.isfile(targetfile)):
os.unlink(targetfile)
# Copy the file
os.link(sourcefile, targetfile)
print " Link: %s" % (targetfile)
# Create root directory
print "Root Directory"
sourcedir = 'ooolib-python'
targetdir = newdir
createdir(targetdir)
copyfiles(sourcedir, targetdir)
# Create ooolib directory
print "ooolib Package Directory"
sourcedir = os.path.join('ooolib-python', 'ooolib')
targetdir = os.path.join(newdir, 'ooolib')
createdir(targetdir)
copyfiles(sourcedir, targetdir, '.py')
# Create examples Directory
print "examples Directory"
sourcedir = os.path.join('ooolib-python', 'examples')
targetdir = os.path.join(newdir, 'examples')
createdir(targetdir)
copyfiles(sourcedir, targetdir, '.py')
# Create package file
print "Building package"
cmd = "tar cvfz %s.tar.gz %s" % (newdir, newdir)
print commands.getoutput(cmd)