forked from dwighthubbard/python-dlipower
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·150 lines (129 loc) · 4.39 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Copyright (c) 2009-2015, Dwight Hubbard
# Copyrights licensed under the New BSD License
# See the accompanying LICENSE.txt file for terms.
import json
import os
from setuptools import setup
import sys
METADATA_FILENAME = 'dlipower/package_metadata.json'
BASEPATH = os.path.dirname(os.path.abspath(__file__))
def readme():
with open('README.rst') as f:
return f.read()
class Git(object):
version_list = ['0', '7', '0']
def __init__(self, version=None):
if version:
self.version_list = version.split('.')
@property
def revision(self):
git_rev = len(os.popen('git rev-list HEAD').readlines())
if git_rev == 0:
git_rev = self.version_list[-1]
return str(git_rev)
@property
def version(self):
"""
Generate a Unique version value from the git information
:return:
"""
self.version_list[-1] = self.revision
version = '.'.join(self.version_list)
return version
@property
def branch(self):
"""
Get the current git branch
:return:
"""
return os.popen('git rev-parse --abbrev-ref HEAD').read().strip()
@property
def hash(self):
"""
Return the git hash for the current build
:return:
"""
return os.popen('git rev-parse HEAD').read().strip()
@property
def origin(self):
"""
Return the fetch url for the git origin
:return:
"""
for item in os.popen('git remote -v'):
split_item = item.strip().split()
if split_item[0] == 'origin' and split_item[-1] == '(push)':
return split_item[1]
def get_and_update_metadata():
"""
Get the package metadata or generate it if missing
:return:
"""
if not os.path.exists('.git') and os.path.exists(METADATA_FILENAME):
with open(METADATA_FILENAME) as fh:
metadata = json.load(fh)
else:
git = Git()
revision = os.environ.get('TRAVIS_BUILD_NUMBER', git.revision)
split_version = git.version.split('.')
split_version[-1] = revision
version = '.'.join(split_version)
metadata = {
'version': version,
'git_hash': git.hash,
'git_origin': git.origin,
'git_branch': git.branch,
'git_version': git.version
}
with open(METADATA_FILENAME, 'w') as fh:
json.dump(metadata, fh)
return metadata
metadata = get_and_update_metadata()
requires = ['six', 'requests', 'beautifulsoup4']
print('Setting up under python version %s' % sys.version)
print('Requirements: %s' % ','.join(requires))
setup(
name="dlipower",
version=metadata['version'],
author="Dwight Hubbard",
author_email="[email protected]",
url="https://github.com/dwighthubbard/python-dlipower/",
license='BSD',
packages=["dlipower"],
scripts=["scripts/dlipower", "scripts/fence_dli"],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Console',
'Intended Audience :: Developers',
'Intended Audience :: System Administrators',
'Intended Audience :: Information Technology',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: BSD :: FreeBSD',
'Operating System :: POSIX :: SunOS/Solaris',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python',
'Topic :: System :: Systems Administration',
'Topic :: Utilities',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: System :: Hardware :: Hardware Drivers',
'Topic :: System :: Power (UPS)',
],
long_description=readme(),
description="Control digital loggers web power switch",
requires=requires,
install_requires=requires,
package_data={
'dlipower': ['package_metadata.json']
},
include_package_data=True,
zip_safe=True,
)