forked from aldebaran/libqicore
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwheel_create.py
134 lines (126 loc) · 4.96 KB
/
wheel_create.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Create the Wheel Package """
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
import os
import sys
import stat
import shutil
from setuptools import sandbox
import six
PATH_HERE = os.path.dirname(os.path.realpath(__file__))
PATH_TEMP = os.path.join(PATH_HERE, "Temp")
UNIXLE_EXTENSIONS = [".py", ".xml", ".json", ".pml", ".txt", ".htm", ".html", ".css"]
UNIXLE_EXCLUDED = [".git", ".dll", ".so", ".pyd", ".dylib"]
def unix_line_ending(folder, extensions=None, excluded=None):
""" Replace Windows Line Endings with Unix Line Endings """
if extensions is None:
extensions = UNIXLE_EXTENSIONS
if excluded is None:
excluded = UNIXLE_EXCLUDED
for dname, _dirs, files in os.walk(folder):
if dname in excluded:
continue
for fname in files:
if fname in excluded:
continue
fext = os.path.splitext(fname)[-1]
if fext not in extensions and fname not in extensions:
continue
fpath = os.path.join(dname, fname)
with open(fpath, "rb") as filer:
fdata = filer.read()
filer.close()
try:
if "\r\n" not in fdata:
continue
except Exception:
continue
with open(fpath, "wb") as filew:
filew.write(fdata.replace("\r\n", "\n"))
filew.close()
print("Unix Line Ending : %s" % fpath)
def folder_cleanup(folder, names=None, extensions=None):
""" Remove all sub folders and files by name or extension """
if not isinstance(names, list):
names = []
if not isinstance(extensions, list):
extensions = []
for dname, dirs, files in os.walk(folder):
for dirname in dirs:
if dirname not in names:
continue
dirpath = os.path.join(dname, dirname)
if os.path.isdir(dirpath):
if not os.access(dirpath, os.W_OK):
os.chmod(dirpath, stat.S_IWRITE)
shutil.rmtree(dirpath, ignore_errors=True)
for fname in files:
fpath = os.path.join(dname, fname)
if fname in names:
if os.path.isfile(fpath):
if not os.access(fpath, os.W_OK):
os.chmod(fpath, stat.S_IWRITE)
os.remove(fpath)
fext = os.path.splitext(fname)[-1]
if fext in extensions or fname in extensions:
if os.path.isfile(fpath):
if not os.access(fpath, os.W_OK):
os.chmod(fpath, stat.S_IWRITE)
os.remove(fpath)
def clean_access_rights(path):
""" Allow write access to a path """
if os.path.isfile(path):
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWRITE)
os.chmod(path, stat.S_IWUSR)
elif os.path.isdir(path):
if not os.access(path, os.W_OK):
os.chmod(path, stat.S_IWRITE)
os.chmod(path, stat.S_IWUSR)
for dname, dirs, files in os.walk(path):
for dirname in dirs:
dirpath = os.path.join(dname, dirname)
if os.path.isdir(dirpath):
if not os.access(dirpath, os.W_OK):
os.chmod(dirpath, stat.S_IWRITE)
os.chmod(dirpath, stat.S_IWUSR)
for fname in files:
fpath = os.path.join(dname, fname)
if os.path.isfile(fpath):
if not os.access(fpath, os.W_OK):
os.chmod(fpath, stat.S_IWRITE)
os.chmod(fpath, stat.S_IWUSR)
def cleanup_folders(dist=False):
""" Prepare the Folders for a platform """
if dist is True:
path_dist = os.path.join(PATH_HERE, "dist")
if os.path.isdir(path_dist):
shutil.rmtree(path_dist, ignore_errors=True)
path_egg = os.path.join(PATH_HERE, "qicore.egg-info")
if os.path.isdir(path_egg):
shutil.rmtree(path_egg, ignore_errors=True)
path_build = os.path.join(PATH_HERE, "build")
if os.path.isdir(path_build):
shutil.rmtree(path_build, ignore_errors=True)
path_temp = os.path.join(PATH_HERE, "temp")
if os.path.isdir(path_temp):
shutil.rmtree(path_temp, ignore_errors=True)
def create():
""" Create a Package """
print("- Clean Access Rights")
clean_access_rights(PATH_HERE)
print("- Remove Building Folders")
cleanup_folders(dist=True)
print("- Clean .pyc Files")
folder_cleanup(PATH_HERE, names=None, extensions=[".pyc"])
unix_line_ending(PATH_HERE, extensions=None, excluded=None)
print("- Build Package")
sandbox.run_setup(os.path.join(PATH_HERE, "setup.py"), ["bdist_wheel"])
print("- Remove Building Folders")
cleanup_folders()
print("- Package Generation Finished")
if __name__ == "__main__":
create()