forked from marcosvella/noc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
134 lines (115 loc) · 3.7 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
#!/usr/bin/env python
# ---------------------------------------------------------------------
# Distutils setup.py
# ---------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
from distutils.core import setup
import distutils.command.sdist
from distutils.command.install import INSTALL_SCHEMES
import subprocess
import os
#
# Prefix to where noc to be installed
#
PREFIX = "/opt/noc"
def get_version():
"""
Read actual NOC version from VERSION file
:return:
"""
with open("VERSION") as f:
return f.read().strip()
MANIFEST = []
def get_manifest():
"""
Build distribution manifest
:return:
"""
global MANIFEST
if not MANIFEST:
if os.path.exists(".hg"):
# Rebuild MANIFEST file every time mercurial repo found
proc = subprocess.Popen(
["hg", "locate"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
stdout, stderr = proc.communicate()
mf = stdout.splitlines()
if os.path.exists(".hgsub"):
with open(".hgsub") as sf:
for l in sf:
if "=" not in l:
continue
sr, r = l.split("=", 1)
sr = sr.strip()
proc = subprocess.Popen(
["hg", "-R", sr, "locate"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = proc.communicate()
mf += [sr + "/" + x for x in stdout.splitlines()]
mf += ["MANIFEST"]
with open("MANIFEST", "w") as f:
f.write("\n".join(mf))
with open("MANIFEST") as f:
MANIFEST = [n for n in f.read().splitlines() if not n.startswith(".hg")]
return MANIFEST
def get_packages():
"""
Return list of packages
:return:
"""
return [""] + [
f[:-12].replace(os.sep, ".")
for f in get_manifest()
if f.endswith("__init__.py") and f != "__init__.py"
]
def get_data():
"""
Return data files
:return:
"""
data = {}
for df in get_manifest():
d, f = os.path.split(df)
if d not in data:
data[d] = [df]
else:
data[d].append(df)
return list(data.items())
class noc_sdist(distutils.command.sdist.sdist):
"""
Get file list for sdist from MANIFEST
"""
def get_file_list(self):
self.filelist.files = get_manifest()
#
# Monkeypatch distutils to install noc to the desired location
#
for scheme in INSTALL_SCHEMES.values():
scheme["purelib"] = PREFIX
scheme["data"] = PREFIX
#
# Pass control to the setuptools
#
setup(
name="noc",
version=get_version(),
description="Network Operation Center's OSS",
author="Dmitry Volodin",
author_email="[email protected]",
url="http://nocproject.org/",
license="BSD",
long_description="""NOC Project is an Operation Support System (OSS) for telecom companies,
service providers, and enterprise Network Operation Centers (NOC).
Areas covered by NOC include fault management, service activation/provisioning, multi-VRF address space management,
configuration management, DNS provisioning, peering management, RPSL and BGP filter generation, and reporting.""",
cmdclass={"sdist": noc_sdist},
packages=get_packages(),
data_files=get_data(),
provides=["noc"],
requires=["psycopg2 (>= 2.0.5)", "pycrypto (>= 2.3)", "pymongo (>= 1.1)"],
)