forked from motom001/DoorPi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
executable file
·130 lines (115 loc) · 4.32 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
import imp
import os
import uuid
import sys
import urllib2
# Check for pip, setuptools and wheel
try:
import pip
import setuptools
import wheel
except ImportError as exp:
print("install missing pip now (%s)" % exp)
from get_pip import main as check_for_pip
old_args = sys.argv
sys.argv = [sys.argv[0]]
try:
check_for_pip()
except SystemExit as e:
if e.code == 0:
os.execv(sys.executable, [sys.executable] + old_args)
else:
print("install pip failed with error code %s" % e.code)
sys.exit(e.code)
base_path = os.path.dirname(os.path.abspath(__file__))
metadata = imp.load_source('metadata', os.path.join(base_path, 'doorpi', 'metadata.py'))
def parse_string(raw_string):
for meta_key in dir(metadata):
if not meta_key.startswith('__'):
raw_string = raw_string.replace('!!%s!!' % meta_key, str(getattr(metadata, meta_key)))
return raw_string
def read(filename, parse_file_content=False, new_filename=None):
with open(os.path.join(base_path, filename)) as f:
file_content = f.read()
if parse_file_content:
file_content = parse_string(file_content)
if new_filename:
with open(os.path.join(base_path, new_filename), 'w') as f:
f.write(file_content)
return new_filename
return file_content
from setuptools import setup, find_packages
try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
install_reqs = parse_requirements(os.path.join(base_path, 'requirements.txt'), session=uuid.uuid1())
reqs = [str(req.req) for req in install_reqs]
setup_dict = dict(
# <http://pythonhosted.org/setuptools/setuptools.html>
license=metadata.license,
name=metadata.package,
version=metadata.version,
author=metadata.authors[0],
author_email=metadata.emails[0],
maintainer=metadata.authors[0],
maintainer_email=metadata.emails[0],
url=metadata.url,
keywords=metadata.keywords,
description=metadata.description,
long_description=read('README.rst'),
# Find a list of classifiers here:
# <http://pypi.python.org/pypi?%3Aaction=list_classifiers>
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Information Technology',
'Intended Audience :: System Administrators',
'License :: Free for non-commercial use',
'Natural Language :: German',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
# 'Programming Language :: Python :: 3.3',
# 'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Documentation',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Installation/Setup',
'Topic :: System :: Software Distribution',
'Topic :: Communications :: Internet Phone',
'Topic :: Communications :: Telephony',
'Topic :: Multimedia :: Sound/Audio :: Capture/Recording',
'Topic :: Multimedia :: Video :: Capture',
'Topic :: Multimedia :: Video :: Conversion',
'Topic :: Security',
'Topic :: System :: Emulators',
'Topic :: System :: Filesystems',
'Topic :: System :: Hardware',
'Topic :: Utilities'
],
packages=find_packages(exclude=['contrib', 'docs', 'tests*']),
install_requires=reqs,
platforms=["any"],
use_2to3=False,
zip_safe=False, # don't use eggs
entry_points={
'console_scripts': [
'doorpi_cli = doorpi.main:entry_point'
]
}
)
def main():
try:
if os.name == 'posix' and os.geteuid() == 0 and \
not os.path.isfile(metadata.daemon_file) and not os.path.exists(metadata.daemon_file):
with open(metadata.daemon_file, "w") as daemon_file:
for line in urllib2.urlopen(metadata.daemon_online_template):
daemon_file.write(parse_string(line))
os.chmod(metadata.daemon_file, 0755)
except: pass
setup(**setup_dict)
if __name__ == '__main__':
main()