-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
113 lines (92 loc) · 3.11 KB
/
setup.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
#!/usr/bin/env python3
import os
import re, sys
from setuptools import setup, find_packages
from setuptools import Command
from shutil import rmtree
class StripSpaces(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def __init__(self):
self.reg = re.compile(r'\s+$')
def stripfn(self, fn):
with open(fn, 'rt', encoding='utf-8') as fd:
s = fd.read()
with open(fn, 'wt', encoding='utf-8') as fd:
for line in s.split('\n'):
s2 = self.reg.sub('', line)
fd.write(f"{s2}\n")
def strip_all(self, bd):
basedir = os.path.realpath(bd)
for dirpath, dirnames, filenames in os.walk(basedir):
if 'bak' in dirnames:
dirnames.remove('bak')
for fn in filenames:
if not fn.endswith('.py'):
continue
fp = os.path.join(dirpath, fn)
if os.path.exists(fp):
self.stripfn(fp)
class CleanCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def clean_subdirs(self, basedir, clean_sfx=["~", ".bak"]):
for rdir, dirs, fns in os.walk(basedir):
for fn in fns:
sys.stdout.write(".")
sys.stdout.flush()
do_rm = False
for chk_sfx in clean_sfx:
if fn.endswith(chk_sfx):
do_rm = True
break
if do_rm:
rmpath = os.path.join(rdir, fn)
print("Unlink path: {}".format(rmpath))
def run(self):
if '__file__' in dir():
basedir = os.path.realpath(os.path.dirname(__file__))
else:
basedir = os.path.realpath('.')
dpath = os.path.join(basedir, 'dist')
bpath = os.path.join(basedir, 'build')
print("Cleaning dist path...")
rmtree(dpath, ignore_errors=True)
print("Cleaning build path...")
rmtree(bpath, ignore_errors=True)
print("Removing garbage files...")
self.clean_subdirs(basedir)
inrel=['blessed>=1.19.0', 'rarfile>=3.1', 'docopt>=0.6.2']
def build_config(**kw):
bcfg = {}
for k in kw:
bcfg[k] = kw[k]
return bcfg
with open('crackid/__init__.py', 'rb') as fd:
s = fd.read().decode('utf-8')
pat = re.search(r'''__version__\s*=\s*\'([^\']+)\'''', s)
if not pat:
print("Unable to determine the verison number from the __init__.py file.")
sys.exit(1)
cid_ver = pat.group(1)
bcfg = build_config(
name='crackid',
version=cid_ver,
packages=find_packages(),
entry_points={
'console_scripts': [ 'crackid=crackid.__main__:main' ]
},
description='ComicRack ComicInfo.xml file reader / consumer',
author='btx',
author_email='[email protected]',
license='MIT',
url='http://donkeykong.net/crackid.tgz',
install_requires=inrel
)
setup(zip_safe=False, cmdclass={ 'distclean': CleanCommand, 'stripspaces': StripSpaces }, **bcfg)