wheel_create.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """ Create the Wheel Package """
4 from __future__ import absolute_import
5 from __future__ import unicode_literals
6 from __future__ import print_function
7 
8 import os
9 import sys
10 import stat
11 import shutil
12 from setuptools import sandbox
13 import six
14 
15 PATH_HERE = os.path.dirname(os.path.realpath(__file__))
16 PATH_TEMP = os.path.join(PATH_HERE, "Temp")
17 UNIXLE_EXTENSIONS = [".py", ".xml", ".json", ".pml", ".txt", ".htm", ".html", ".css"]
18 UNIXLE_EXCLUDED = [".git", ".dll", ".so", ".pyd", ".dylib"]
19 
20 def unix_line_ending(folder, extensions=None, excluded=None):
21  """ Replace Windows Line Endings with Unix Line Endings """
22  if extensions is None:
23  extensions = UNIXLE_EXTENSIONS
24  if excluded is None:
25  excluded = UNIXLE_EXCLUDED
26  for dname, _dirs, files in os.walk(folder):
27  if dname in excluded:
28  continue
29  for fname in files:
30  if fname in excluded:
31  continue
32  fext = os.path.splitext(fname)[-1]
33  if fext not in extensions and fname not in extensions:
34  continue
35  fpath = os.path.join(dname, fname)
36  with open(fpath, "rb") as filer:
37  fdata = filer.read()
38  filer.close()
39  try:
40  if "\r\n" not in fdata:
41  continue
42  except Exception:
43  continue
44  with open(fpath, "wb") as filew:
45  filew.write(fdata.replace("\r\n", "\n"))
46  filew.close()
47  print("Unix Line Ending : %s" % fpath)
48 
49 def folder_cleanup(folder, names=None, extensions=None):
50  """ Remove all sub folders and files by name or extension """
51  if not isinstance(names, list):
52  names = []
53  if not isinstance(extensions, list):
54  extensions = []
55  for dname, dirs, files in os.walk(folder):
56  for dirname in dirs:
57  if dirname not in names:
58  continue
59  dirpath = os.path.join(dname, dirname)
60  if os.path.isdir(dirpath):
61  if not os.access(dirpath, os.W_OK):
62  os.chmod(dirpath, stat.S_IWRITE)
63  shutil.rmtree(dirpath, ignore_errors=True)
64  for fname in files:
65  fpath = os.path.join(dname, fname)
66  if fname in names:
67  if os.path.isfile(fpath):
68  if not os.access(fpath, os.W_OK):
69  os.chmod(fpath, stat.S_IWRITE)
70  os.remove(fpath)
71  fext = os.path.splitext(fname)[-1]
72  if fext in extensions or fname in extensions:
73  if os.path.isfile(fpath):
74  if not os.access(fpath, os.W_OK):
75  os.chmod(fpath, stat.S_IWRITE)
76  os.remove(fpath)
77 
79  """ Allow write access to a path """
80  if os.path.isfile(path):
81  if not os.access(path, os.W_OK):
82  os.chmod(path, stat.S_IWRITE)
83  os.chmod(path, stat.S_IWUSR)
84  elif os.path.isdir(path):
85  if not os.access(path, os.W_OK):
86  os.chmod(path, stat.S_IWRITE)
87  os.chmod(path, stat.S_IWUSR)
88  for dname, dirs, files in os.walk(path):
89  for dirname in dirs:
90  dirpath = os.path.join(dname, dirname)
91  if os.path.isdir(dirpath):
92  if not os.access(dirpath, os.W_OK):
93  os.chmod(dirpath, stat.S_IWRITE)
94  os.chmod(dirpath, stat.S_IWUSR)
95  for fname in files:
96  fpath = os.path.join(dname, fname)
97  if os.path.isfile(fpath):
98  if not os.access(fpath, os.W_OK):
99  os.chmod(fpath, stat.S_IWRITE)
100  os.chmod(fpath, stat.S_IWUSR)
101 
102 def cleanup_folders(dist=False):
103  """ Prepare the Folders for a platform """
104  if dist is True:
105  path_dist = os.path.join(PATH_HERE, "dist")
106  if os.path.isdir(path_dist):
107  shutil.rmtree(path_dist, ignore_errors=True)
108  path_egg = os.path.join(PATH_HERE, "qicore.egg-info")
109  if os.path.isdir(path_egg):
110  shutil.rmtree(path_egg, ignore_errors=True)
111  path_build = os.path.join(PATH_HERE, "build")
112  if os.path.isdir(path_build):
113  shutil.rmtree(path_build, ignore_errors=True)
114  path_temp = os.path.join(PATH_HERE, "temp")
115  if os.path.isdir(path_temp):
116  shutil.rmtree(path_temp, ignore_errors=True)
117 
118 def create():
119  """ Create a Package """
120  print("- Clean Access Rights")
121  clean_access_rights(PATH_HERE)
122  print("- Remove Building Folders")
123  cleanup_folders(dist=True)
124  print("- Clean .pyc Files")
125  folder_cleanup(PATH_HERE, names=None, extensions=[".pyc"])
126  unix_line_ending(PATH_HERE, extensions=None, excluded=None)
127  print("- Build Package")
128  sandbox.run_setup(os.path.join(PATH_HERE, "setup.py"), ["bdist_wheel"])
129  print("- Remove Building Folders")
131  print("- Package Generation Finished")
132 
133 if __name__ == "__main__":
134  create()
wheel_create.clean_access_rights
def clean_access_rights(path)
Definition: wheel_create.py:78
wheel_create.cleanup_folders
def cleanup_folders(dist=False)
Definition: wheel_create.py:102
wheel_create.create
def create()
Definition: wheel_create.py:118
wheel_create.folder_cleanup
def folder_cleanup(folder, names=None, extensions=None)
Definition: wheel_create.py:49
wheel_create.unix_line_ending
def unix_line_ending(folder, extensions=None, excluded=None)
Definition: wheel_create.py:20


naoqi_libqicore
Author(s): Aldebaran
autogenerated on Wed Sep 14 2022 02:22:41