This repository has been archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzipper.py
57 lines (48 loc) · 1.75 KB
/
zipper.py
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
'''zipper.py - create the extension .zip file
This creates a zip file suitable for uploading to the extension registry.
'''
'''
given a string like "foo/bar/baz", I need to "mkdir" foo/bar"
'''
from zipfile import ZipFile, ZIP_STORED
import os
import json
from pprint import pprint
import glob
import shutil
class Zipper(object):
def __init__(self):
with open("package.json", "r") as f:
self.package = json.load(f)
self.root = "brackets-robotframework"
here = os.path.dirname(__file__)
zipname = "%s-%s.zip" % (self.root, self.package["version"])
self.filename = os.path.join(here, "build", zipname)
self._dirs = []
def _add(self, zf, path):
print "+",path
if os.path.isdir(path):
for filename in glob.glob(path + "/*"):
self._add(zf, filename)
else:
dirname = os.path.dirname(path)
self._mkZipDir(zf, dirname)
zf.write(path, os.path.join(self.root,path))
def _mkZipDir(self, zf, path):
if os.path.isdir(path) and path not in self._dirs:
zf.write(path, os.path.join(self.root, path), compress_type = ZIP_STORED)
self._dirs.append(path)
def zip(self):
with ZipFile(self.filename, "w") as zf:
self._mkZipDir(zf, ".")
self._mkZipDir(zf, "node")
self._mkZipDir(zf, "node/node_modules")
self._mkZipDir(zf, "templates")
# zf.write(".", self.root, compress_type = ZIP_STORED)
for pattern in self.package["files"]:
for filename in glob.glob(pattern):
self._add(zf, filename)
print "created", self.filename
if __name__ == "__main__":
zipper = Zipper()
zipper.zip()