| 1 |
import os |
|---|
| 2 |
import sys |
|---|
| 3 |
import shutil |
|---|
| 4 |
import zipfile |
|---|
| 5 |
|
|---|
| 6 |
def truncatePath(top, path): |
|---|
| 7 |
path = path.split(os.sep) |
|---|
| 8 |
top = top.split(os.sep) |
|---|
| 9 |
truncated = list(path) |
|---|
| 10 |
for i in path: |
|---|
| 11 |
if not top: |
|---|
| 12 |
break |
|---|
| 13 |
if i == top[0]: |
|---|
| 14 |
truncated = truncated[1:] |
|---|
| 15 |
top = top[1:] |
|---|
| 16 |
else: |
|---|
| 17 |
break |
|---|
| 18 |
return os.sep.join(truncated) |
|---|
| 19 |
|
|---|
| 20 |
def gatherFiles(dir, top=""): |
|---|
| 21 |
entries = [] |
|---|
| 22 |
for fileName in os.listdir(dir): |
|---|
| 23 |
if fileName.startswith('.'): |
|---|
| 24 |
continue |
|---|
| 25 |
if fileName.endswith('.pyc'): |
|---|
| 26 |
continue |
|---|
| 27 |
fullFileName = os.path.join(dir, fileName) |
|---|
| 28 |
if os.path.isdir(fullFileName): |
|---|
| 29 |
otherEntries = gatherFiles(fullFileName, top) |
|---|
| 30 |
entries.extend(otherEntries) |
|---|
| 31 |
else: |
|---|
| 32 |
fullFileName = truncatePath(top, fullFileName) |
|---|
| 33 |
entries.append(fullFileName) |
|---|
| 34 |
return entries |
|---|
| 35 |
|
|---|
| 36 |
def copyFiles(srcDir, dstDir, entries): |
|---|
| 37 |
for entry in entries: |
|---|
| 38 |
src = os.path.join(srcDir, entry) |
|---|
| 39 |
dst = os.path.join(dstDir, entry) |
|---|
| 40 |
dir = os.path.dirname(dst) |
|---|
| 41 |
if not os.path.exists(dir): |
|---|
| 42 |
os.makedirs(dir) |
|---|
| 43 |
try: |
|---|
| 44 |
shutil.copy(src, dst) |
|---|
| 45 |
except IOError: |
|---|
| 46 |
print "#### makeDistro warns: Source missing (copying): ", src |
|---|
| 47 |
continue |
|---|
| 48 |
|
|---|
| 49 |
def addFiles(zipArchive, srcDir, entries): |
|---|
| 50 |
"""Add files to zip archive.""" |
|---|
| 51 |
for entry in entries: |
|---|
| 52 |
src = os.path.join(srcDir, entry) |
|---|
| 53 |
if not os.path.exists(src): |
|---|
| 54 |
print "#### makeDistro warns: Source missing (zipping): ", src |
|---|
| 55 |
continue |
|---|
| 56 |
zipArchive.write(src, entry) |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
import dialogKit |
|---|
| 61 |
|
|---|
| 62 |
dkDir = os.path.dirname(os.path.dirname(os.path.dirname(dialogKit.__file__))) |
|---|
| 63 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
distDir = os.path.join(dkDir, "Distributions") |
|---|
| 67 |
|
|---|
| 68 |
if os.path.exists(distDir): |
|---|
| 69 |
shutil.rmtree(distDir) |
|---|
| 70 |
os.mkdir(distDir) |
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
print "Gathering files..." |
|---|
| 75 |
|
|---|
| 76 |
dkFiles = gatherFiles(dkDir, dkDir) |
|---|
| 77 |
dkFiles.sort() |
|---|
| 78 |
|
|---|
| 79 |
exclude = ['makeDistro.py'] |
|---|
| 80 |
|
|---|
| 81 |
dkFiles = [i for i in dkFiles if i not in exclude] |
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
print "Copying files to folders..." |
|---|
| 86 |
|
|---|
| 87 |
dkName = "dialogKit_%s" % dialogKit.version |
|---|
| 88 |
|
|---|
| 89 |
dkDist = os.path.join(distDir, dkName) |
|---|
| 90 |
|
|---|
| 91 |
copyFiles(dkDir, dkDist, dkFiles) |
|---|
| 92 |
|
|---|
| 93 |
dkZip = zipfile.ZipFile(os.path.join(distDir, dkName + ".zip"), |
|---|
| 94 |
"w", zipfile.ZIP_DEFLATED) |
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
print "Writing zip file..." |
|---|
| 99 |
|
|---|
| 100 |
addFiles(dkZip, dkDir, dkFiles) |
|---|
| 101 |
dkZip.close() |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
print "Done." |
|---|