setup.py 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. '''
  4. The setup script for salt
  5. '''
  6. # pylint: disable=file-perms,ungrouped-imports,wrong-import-order,wrong-import-position,repr-flag-used-in-string
  7. # pylint: disable=3rd-party-local-module-not-gated,resource-leakage
  8. # pylint: disable=C0111,E1101,E1103,F0401,W0611,W0201,W0232,R0201,R0902,R0903
  9. # For Python 2.5. A no-op on 2.6 and above.
  10. from __future__ import absolute_import, print_function, with_statement
  11. import os
  12. import sys
  13. import glob
  14. import time
  15. import operator
  16. import platform
  17. try:
  18. from urllib2 import urlopen
  19. except ImportError:
  20. from urllib.request import urlopen # pylint: disable=no-name-in-module
  21. from datetime import datetime
  22. # pylint: disable=E0611
  23. import distutils.dist
  24. from distutils import log
  25. from distutils.cmd import Command
  26. from distutils.errors import DistutilsArgError
  27. from distutils.command.build import build
  28. from distutils.command.clean import clean
  29. from distutils.command.sdist import sdist
  30. from distutils.command.install_lib import install_lib
  31. from distutils.version import LooseVersion # pylint: disable=blacklisted-module
  32. from ctypes.util import find_library
  33. # pylint: enable=E0611
  34. try:
  35. import zmq
  36. HAS_ZMQ = True
  37. except ImportError:
  38. HAS_ZMQ = False
  39. try:
  40. DATE = datetime.utcfromtimestamp(int(os.environ['SOURCE_DATE_EPOCH']))
  41. except (KeyError, ValueError):
  42. DATE = datetime.utcnow()
  43. # Change to salt source's directory prior to running any command
  44. try:
  45. SETUP_DIRNAME = os.path.dirname(__file__)
  46. except NameError:
  47. # We're most likely being frozen and __file__ triggered this NameError
  48. # Let's work around that
  49. SETUP_DIRNAME = os.path.dirname(sys.argv[0])
  50. if SETUP_DIRNAME != '':
  51. os.chdir(SETUP_DIRNAME)
  52. SETUP_DIRNAME = os.path.abspath(SETUP_DIRNAME)
  53. BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION = os.environ.get(
  54. # The user can provide a different bootstrap-script version.
  55. # ATTENTION: A tag for that version MUST exist
  56. 'BOOTSTRAP_SCRIPT_VERSION',
  57. # If no bootstrap-script version was provided from the environment, let's
  58. # provide the one we define.
  59. 'v2014.06.21'
  60. )
  61. # Store a reference to the executing platform
  62. IS_WINDOWS_PLATFORM = sys.platform.startswith('win')
  63. if IS_WINDOWS_PLATFORM:
  64. IS_SMARTOS_PLATFORM = False
  65. else:
  66. # os.uname() not available on Windows.
  67. IS_SMARTOS_PLATFORM = os.uname()[0] == 'SunOS' and os.uname()[3].startswith('joyent_')
  68. # Store a reference whether if we're running under Python 3 and above
  69. IS_PY3 = sys.version_info > (3,)
  70. # Use setuptools only if the user opts-in by setting the USE_SETUPTOOLS env var
  71. # Or if setuptools was previously imported (which is the case when using
  72. # 'distribute')
  73. # This ensures consistent behavior but allows for advanced usage with
  74. # virtualenv, buildout, and others.
  75. WITH_SETUPTOOLS = False
  76. if 'USE_SETUPTOOLS' in os.environ or 'setuptools' in sys.modules:
  77. try:
  78. from setuptools import setup
  79. from setuptools.command.develop import develop
  80. from setuptools.command.install import install
  81. from setuptools.command.sdist import sdist
  82. from setuptools.command.egg_info import egg_info
  83. WITH_SETUPTOOLS = True
  84. except ImportError:
  85. WITH_SETUPTOOLS = False
  86. if WITH_SETUPTOOLS is False:
  87. import warnings
  88. # pylint: disable=E0611
  89. from distutils.command.install import install
  90. from distutils.core import setup
  91. # pylint: enable=E0611
  92. warnings.filterwarnings(
  93. 'ignore',
  94. 'Unknown distribution option: \'(extras_require|tests_require|install_requires|zip_safe)\'',
  95. UserWarning,
  96. 'distutils.dist'
  97. )
  98. try:
  99. # Add the esky bdist target if the module is available
  100. # may require additional modules depending on platform
  101. from esky import bdist_esky
  102. # bbfreeze chosen for its tight integration with distutils
  103. import bbfreeze
  104. HAS_ESKY = True
  105. except ImportError:
  106. HAS_ESKY = False
  107. SALT_VERSION = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', 'version.py')
  108. SALT_VERSION_HARDCODED = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', '_version.py')
  109. SALT_SYSPATHS_HARDCODED = os.path.join(os.path.abspath(SETUP_DIRNAME), 'salt', '_syspaths.py')
  110. SALT_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'requirements', 'base.txt')
  111. SALT_ZEROMQ_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'requirements', 'zeromq.txt')
  112. SALT_WINDOWS_REQS = os.path.join(os.path.abspath(SETUP_DIRNAME), 'pkg', 'windows', 'req.txt')
  113. SALT_LONG_DESCRIPTION_FILE = os.path.join(os.path.abspath(SETUP_DIRNAME), 'README.rst')
  114. # Salt SSH Packaging Detection
  115. PACKAGED_FOR_SALT_SSH_FILE = os.path.join(os.path.abspath(SETUP_DIRNAME), '.salt-ssh-package')
  116. PACKAGED_FOR_SALT_SSH = os.path.isfile(PACKAGED_FOR_SALT_SSH_FILE)
  117. # pylint: disable=W0122
  118. exec(compile(open(SALT_VERSION).read(), SALT_VERSION, 'exec'))
  119. # pylint: enable=W0122
  120. # ----- Helper Functions -------------------------------------------------------------------------------------------->
  121. def _parse_op(op):
  122. '''
  123. >>> _parse_op('>')
  124. 'gt'
  125. >>> _parse_op('>=')
  126. 'ge'
  127. >>> _parse_op('=>')
  128. 'ge'
  129. >>> _parse_op('=> ')
  130. 'ge'
  131. >>> _parse_op('<')
  132. 'lt'
  133. >>> _parse_op('<=')
  134. 'le'
  135. >>> _parse_op('==')
  136. 'eq'
  137. >>> _parse_op(' <= ')
  138. 'le'
  139. '''
  140. op = op.strip()
  141. if '>' in op:
  142. if '=' in op:
  143. return 'ge'
  144. else:
  145. return 'gt'
  146. elif '<' in op:
  147. if '=' in op:
  148. return 'le'
  149. else:
  150. return 'lt'
  151. elif '!' in op:
  152. return 'ne'
  153. else:
  154. return 'eq'
  155. def _parse_ver(ver):
  156. '''
  157. >>> _parse_ver("'3.4' # pyzmq 17.1.0 stopped building wheels for python3.4")
  158. '3.4'
  159. >>> _parse_ver('"3.4"')
  160. '3.4'
  161. >>> _parse_ver('"2.6.17"')
  162. '2.6.17'
  163. '''
  164. if '#' in ver:
  165. ver, _ = ver.split('#', 1)
  166. ver = ver.strip()
  167. return ver.strip('\'').strip('"')
  168. def _check_ver(pyver, op, wanted):
  169. '''
  170. >>> _check_ver('2.7.15', 'gt', '2.7')
  171. True
  172. >>> _check_ver('2.7.15', 'gt', '2.7.15')
  173. False
  174. >>> _check_ver('2.7.15', 'ge', '2.7.15')
  175. True
  176. >>> _check_ver('2.7.15', 'eq', '2.7.15')
  177. True
  178. '''
  179. pyver = distutils.version.LooseVersion(pyver)
  180. wanted = distutils.version.LooseVersion(wanted)
  181. if IS_PY3:
  182. if not isinstance(pyver, str):
  183. pyver = str(pyver)
  184. if not isinstance(wanted, str):
  185. wanted = str(wanted)
  186. return getattr(operator, '__{}__'.format(op))(pyver, wanted)
  187. def _parse_requirements_file(requirements_file):
  188. parsed_requirements = []
  189. with open(requirements_file) as rfh:
  190. for line in rfh.readlines():
  191. line = line.strip()
  192. if not line or line.startswith(('#', '-r')):
  193. continue
  194. if IS_WINDOWS_PLATFORM:
  195. if 'libcloud' in line:
  196. continue
  197. if IS_PY3 and 'futures' in line.lower():
  198. # Python 3 already has futures, installing it will only break
  199. # the current python installation whenever futures is imported
  200. continue
  201. try:
  202. pkg, pyverspec = line.rsplit(';', 1)
  203. except ValueError:
  204. pkg, pyverspec = line, ''
  205. pyverspec = pyverspec.strip()
  206. if pyverspec:
  207. _, op, ver = pyverspec.split(' ', 2)
  208. if not _check_ver(platform.python_version(), _parse_op(op), _parse_ver(ver)):
  209. continue
  210. parsed_requirements.append(pkg)
  211. return parsed_requirements
  212. # <---- Helper Functions ---------------------------------------------------------------------------------------------
  213. # ----- Custom Distutils/Setuptools Commands ------------------------------------------------------------------------>
  214. class WriteSaltVersion(Command):
  215. description = 'Write salt\'s hardcoded version file'
  216. user_options = []
  217. def initialize_options(self):
  218. '''
  219. Abstract method that is required to be overwritten
  220. '''
  221. def finalize_options(self):
  222. '''
  223. Abstract method that is required to be overwritten
  224. '''
  225. def run(self):
  226. if not os.path.exists(SALT_VERSION_HARDCODED) or self.distribution.with_salt_version:
  227. # Write the version file
  228. if getattr(self.distribution, 'salt_version_hardcoded_path', None) is None:
  229. print('This command is not meant to be called on it\'s own')
  230. exit(1)
  231. if not self.distribution.with_salt_version:
  232. salt_version = __saltstack_version__ # pylint: disable=undefined-variable
  233. else:
  234. from salt.version import SaltStackVersion
  235. salt_version = SaltStackVersion.parse(self.distribution.with_salt_version)
  236. # pylint: disable=E0602
  237. open(self.distribution.salt_version_hardcoded_path, 'w').write(
  238. INSTALL_VERSION_TEMPLATE.format(
  239. date=DATE,
  240. full_version_info=salt_version.full_info
  241. )
  242. )
  243. # pylint: enable=E0602
  244. class GenerateSaltSyspaths(Command):
  245. description = 'Generate salt\'s hardcoded syspaths file'
  246. def initialize_options(self):
  247. pass
  248. def finalize_options(self):
  249. pass
  250. def run(self):
  251. # Write the syspaths file
  252. if getattr(self.distribution, 'salt_syspaths_hardcoded_path', None) is None:
  253. print('This command is not meant to be called on it\'s own')
  254. exit(1)
  255. # Write the system paths file
  256. open(self.distribution.salt_syspaths_hardcoded_path, 'w').write(
  257. INSTALL_SYSPATHS_TEMPLATE.format(
  258. date=DATE,
  259. root_dir=self.distribution.salt_root_dir,
  260. share_dir=self.distribution.salt_share_dir,
  261. config_dir=self.distribution.salt_config_dir,
  262. cache_dir=self.distribution.salt_cache_dir,
  263. sock_dir=self.distribution.salt_sock_dir,
  264. srv_root_dir=self.distribution.salt_srv_root_dir,
  265. base_file_roots_dir=self.distribution.salt_base_file_roots_dir,
  266. base_pillar_roots_dir=self.distribution.salt_base_pillar_roots_dir,
  267. base_master_roots_dir=self.distribution.salt_base_master_roots_dir,
  268. base_thorium_roots_dir=self.distribution.salt_base_thorium_roots_dir,
  269. logs_dir=self.distribution.salt_logs_dir,
  270. pidfile_dir=self.distribution.salt_pidfile_dir,
  271. spm_parent_path=self.distribution.salt_spm_parent_dir,
  272. spm_formula_path=self.distribution.salt_spm_formula_dir,
  273. spm_pillar_path=self.distribution.salt_spm_pillar_dir,
  274. spm_reactor_path=self.distribution.salt_spm_reactor_dir,
  275. home_dir=self.distribution.salt_home_dir,
  276. )
  277. )
  278. class WriteSaltSshPackagingFile(Command):
  279. description = 'Write salt\'s ssh packaging file'
  280. user_options = []
  281. def initialize_options(self):
  282. '''
  283. Abstract method that is required to be overwritten
  284. '''
  285. def finalize_options(self):
  286. '''
  287. Abstract method that is required to be overwritten
  288. '''
  289. def run(self):
  290. if not os.path.exists(PACKAGED_FOR_SALT_SSH_FILE):
  291. # Write the salt-ssh packaging file
  292. if getattr(self.distribution, 'salt_ssh_packaging_file', None) is None:
  293. print('This command is not meant to be called on it\'s own')
  294. exit(1)
  295. # pylint: disable=E0602
  296. open(self.distribution.salt_ssh_packaging_file, 'w').write('Packaged for Salt-SSH\n')
  297. # pylint: enable=E0602
  298. if WITH_SETUPTOOLS:
  299. class Develop(develop):
  300. user_options = develop.user_options + [
  301. ('write-salt-version', None,
  302. 'Generate Salt\'s _version.py file which allows proper version '
  303. 'reporting. This defaults to False on develop/editable setups. '
  304. 'If WRITE_SALT_VERSION is found in the environment this flag is '
  305. 'switched to True.'),
  306. ('generate-salt-syspaths', None,
  307. 'Generate Salt\'s _syspaths.py file which allows tweaking some '
  308. 'common paths that salt uses. This defaults to False on '
  309. 'develop/editable setups. If GENERATE_SALT_SYSPATHS is found in '
  310. 'the environment this flag is switched to True.'),
  311. ('mimic-salt-install', None,
  312. 'Mimmic the install command when running the develop command. '
  313. 'This will generate salt\'s _version.py and _syspaths.py files. '
  314. 'Generate Salt\'s _syspaths.py file which allows tweaking some '
  315. 'This defaults to False on develop/editable setups. '
  316. 'If MIMIC_INSTALL is found in the environment this flag is '
  317. 'switched to True.')
  318. ]
  319. boolean_options = develop.boolean_options + [
  320. 'write-salt-version',
  321. 'generate-salt-syspaths',
  322. 'mimic-salt-install'
  323. ]
  324. def initialize_options(self):
  325. develop.initialize_options(self)
  326. self.write_salt_version = False
  327. self.generate_salt_syspaths = False
  328. self.mimic_salt_install = False
  329. def finalize_options(self):
  330. develop.finalize_options(self)
  331. if 'WRITE_SALT_VERSION' in os.environ:
  332. self.write_salt_version = True
  333. if 'GENERATE_SALT_SYSPATHS' in os.environ:
  334. self.generate_salt_syspaths = True
  335. if 'MIMIC_SALT_INSTALL' in os.environ:
  336. self.mimic_salt_install = True
  337. if self.mimic_salt_install:
  338. self.write_salt_version = True
  339. self.generate_salt_syspaths = True
  340. def run(self):
  341. if IS_WINDOWS_PLATFORM:
  342. # Download the required DLLs
  343. self.distribution.salt_download_windows_dlls = True
  344. self.run_command('download-windows-dlls')
  345. self.distribution.salt_download_windows_dlls = None
  346. if self.write_salt_version is True:
  347. self.distribution.running_salt_install = True
  348. self.distribution.salt_version_hardcoded_path = SALT_VERSION_HARDCODED
  349. self.run_command('write_salt_version')
  350. if self.generate_salt_syspaths:
  351. self.distribution.salt_syspaths_hardcoded_path = SALT_SYSPATHS_HARDCODED
  352. self.run_command('generate_salt_syspaths')
  353. # Resume normal execution
  354. develop.run(self)
  355. class DownloadWindowsDlls(Command):
  356. description = 'Download required DLL\'s for windows'
  357. def initialize_options(self):
  358. pass
  359. def finalize_options(self):
  360. pass
  361. def run(self):
  362. if getattr(self.distribution, 'salt_download_windows_dlls', None) is None:
  363. print('This command is not meant to be called on it\'s own')
  364. exit(1)
  365. import pip
  366. # pip has moved many things to `_internal` starting with pip 10
  367. if LooseVersion(pip.__version__) < LooseVersion('10.0'):
  368. from pip.utils.logging import indent_log # pylint: disable=no-name-in-module
  369. else:
  370. from pip._internal.utils.logging import indent_log # pylint: disable=no-name-in-module
  371. platform_bits, _ = platform.architecture()
  372. url = 'https://repo.saltstack.com/windows/dependencies/{bits}/{fname}.dll'
  373. dest = os.path.join(os.path.dirname(sys.executable), '{fname}.dll')
  374. with indent_log():
  375. for fname in ('libeay32', 'ssleay32', 'msvcr120'):
  376. # See if the library is already on the system
  377. if find_library(fname):
  378. continue
  379. furl = url.format(bits=platform_bits[:2], fname=fname)
  380. fdest = dest.format(fname=fname)
  381. if not os.path.exists(fdest):
  382. log.info('Downloading {0}.dll to {1} from {2}'.format(fname, fdest, furl))
  383. try:
  384. import requests
  385. from contextlib import closing
  386. with closing(requests.get(furl, stream=True)) as req:
  387. if req.status_code == 200:
  388. with open(fdest, 'wb') as wfh:
  389. for chunk in req.iter_content(chunk_size=4096):
  390. if chunk: # filter out keep-alive new chunks
  391. wfh.write(chunk)
  392. wfh.flush()
  393. else:
  394. log.error(
  395. 'Failed to download {0}.dll to {1} from {2}'.format(
  396. fname, fdest, furl
  397. )
  398. )
  399. except ImportError:
  400. req = urlopen(furl)
  401. if req.getcode() == 200:
  402. with open(fdest, 'wb') as wfh:
  403. if IS_PY3:
  404. while True:
  405. chunk = req.read(4096)
  406. if len(chunk) == 0:
  407. break
  408. wfh.write(chunk)
  409. wfh.flush()
  410. else:
  411. while True:
  412. for chunk in req.read(4096):
  413. if not chunk:
  414. break
  415. wfh.write(chunk)
  416. wfh.flush()
  417. else:
  418. log.error(
  419. 'Failed to download {0}.dll to {1} from {2}'.format(
  420. fname, fdest, furl
  421. )
  422. )
  423. class Sdist(sdist):
  424. def make_release_tree(self, base_dir, files):
  425. if self.distribution.ssh_packaging:
  426. self.distribution.salt_ssh_packaging_file = PACKAGED_FOR_SALT_SSH_FILE
  427. self.run_command('write_salt_ssh_packaging_file')
  428. self.filelist.files.append(os.path.basename(PACKAGED_FOR_SALT_SSH_FILE))
  429. if not IS_PY3 and not isinstance(base_dir, str):
  430. # Work around some bad code in distutils which logs unicode paths
  431. # against a str format string.
  432. base_dir = base_dir.encode('utf-8')
  433. sdist.make_release_tree(self, base_dir, files)
  434. # Let's generate salt/_version.py to include in the sdist tarball
  435. self.distribution.running_salt_sdist = True
  436. self.distribution.salt_version_hardcoded_path = os.path.join(
  437. base_dir, 'salt', '_version.py'
  438. )
  439. self.run_command('write_salt_version')
  440. def make_distribution(self):
  441. sdist.make_distribution(self)
  442. if self.distribution.ssh_packaging:
  443. os.unlink(PACKAGED_FOR_SALT_SSH_FILE)
  444. class CloudSdist(Sdist): # pylint: disable=too-many-ancestors
  445. user_options = Sdist.user_options + [
  446. ('download-bootstrap-script', None,
  447. 'Download the latest stable bootstrap-salt.sh script. This '
  448. 'can also be triggered by having `DOWNLOAD_BOOTSTRAP_SCRIPT=1` as an '
  449. 'environment variable.')
  450. ]
  451. boolean_options = Sdist.boolean_options + [
  452. 'download-bootstrap-script'
  453. ]
  454. def initialize_options(self):
  455. Sdist.initialize_options(self)
  456. self.skip_bootstrap_download = True
  457. self.download_bootstrap_script = False
  458. def finalize_options(self):
  459. Sdist.finalize_options(self)
  460. if 'SKIP_BOOTSTRAP_DOWNLOAD' in os.environ:
  461. log('Please stop using \'SKIP_BOOTSTRAP_DOWNLOAD\' and use ' # pylint: disable=not-callable
  462. '\'DOWNLOAD_BOOTSTRAP_SCRIPT\' instead')
  463. if 'DOWNLOAD_BOOTSTRAP_SCRIPT' in os.environ:
  464. download_bootstrap_script = os.environ.get(
  465. 'DOWNLOAD_BOOTSTRAP_SCRIPT', '0'
  466. )
  467. self.download_bootstrap_script = download_bootstrap_script == '1'
  468. def run(self):
  469. if self.download_bootstrap_script is True:
  470. # Let's update the bootstrap-script to the version defined to be
  471. # distributed. See BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION above.
  472. url = (
  473. 'https://github.com/saltstack/salt-bootstrap/raw/{0}'
  474. '/bootstrap-salt.sh'.format(
  475. BOOTSTRAP_SCRIPT_DISTRIBUTED_VERSION
  476. )
  477. )
  478. deploy_path = os.path.join(
  479. SETUP_DIRNAME,
  480. 'salt',
  481. 'cloud',
  482. 'deploy',
  483. 'bootstrap-salt.sh'
  484. )
  485. log.info(
  486. 'Updating bootstrap-salt.sh.'
  487. '\n\tSource: {0}'
  488. '\n\tDestination: {1}'.format(
  489. url,
  490. deploy_path
  491. )
  492. )
  493. try:
  494. import requests
  495. req = requests.get(url)
  496. if req.status_code == 200:
  497. script_contents = req.text.encode(req.encoding)
  498. else:
  499. log.error(
  500. 'Failed to update the bootstrap-salt.sh script. HTTP '
  501. 'Error code: {0}'.format(
  502. req.status_code
  503. )
  504. )
  505. except ImportError:
  506. req = urlopen(url)
  507. if req.getcode() == 200:
  508. script_contents = req.read()
  509. else:
  510. log.error(
  511. 'Failed to update the bootstrap-salt.sh script. HTTP '
  512. 'Error code: {0}'.format(
  513. req.getcode()
  514. )
  515. )
  516. try:
  517. with open(deploy_path, 'w') as fp_:
  518. fp_.write(script_contents)
  519. except (OSError, IOError) as err:
  520. log.error(
  521. 'Failed to write the updated script: {0}'.format(err)
  522. )
  523. # Let's the rest of the build command
  524. Sdist.run(self)
  525. def write_manifest(self):
  526. # We only need to ship the scripts which are supposed to be installed
  527. dist_scripts = self.distribution.scripts
  528. for script in self.filelist.files[:]:
  529. if not script.startswith('scripts/'):
  530. continue
  531. if script not in dist_scripts:
  532. self.filelist.files.remove(script)
  533. return Sdist.write_manifest(self)
  534. class TestCommand(Command):
  535. description = 'Run tests'
  536. user_options = [
  537. ('runtests-opts=', 'R', 'Command line options to pass to runtests.py')
  538. ]
  539. def initialize_options(self):
  540. self.runtests_opts = None
  541. def finalize_options(self):
  542. '''
  543. Abstract method that is required to be overwritten
  544. '''
  545. def run(self):
  546. from subprocess import Popen
  547. self.run_command('build')
  548. build_cmd = self.get_finalized_command('build_ext')
  549. runner = os.path.abspath('tests/runtests.py')
  550. test_cmd = sys.executable + ' {0}'.format(runner)
  551. if self.runtests_opts:
  552. test_cmd += ' {0}'.format(self.runtests_opts)
  553. print('running test')
  554. test_process = Popen(
  555. test_cmd, shell=True,
  556. stdout=sys.stdout, stderr=sys.stderr,
  557. cwd=build_cmd.build_lib
  558. )
  559. test_process.communicate()
  560. sys.exit(test_process.returncode)
  561. class Clean(clean):
  562. def run(self):
  563. clean.run(self)
  564. # Let's clean compiled *.py[c,o]
  565. for subdir in ('salt', 'tests', 'doc'):
  566. root = os.path.join(os.path.dirname(__file__), subdir)
  567. for dirname, _, _ in os.walk(root):
  568. for to_remove_filename in glob.glob('{0}/*.py[oc]'.format(dirname)):
  569. os.remove(to_remove_filename)
  570. INSTALL_VERSION_TEMPLATE = '''\
  571. # This file was auto-generated by salt's setup
  572. from salt.version import SaltStackVersion
  573. __saltstack_version__ = SaltStackVersion{full_version_info!r}
  574. '''
  575. INSTALL_SYSPATHS_TEMPLATE = '''\
  576. # This file was auto-generated by salt's setup on \
  577. {date:%A, %d %B %Y @ %H:%m:%S UTC}.
  578. ROOT_DIR = {root_dir!r}
  579. SHARE_DIR = {share_dir!r}
  580. CONFIG_DIR = {config_dir!r}
  581. CACHE_DIR = {cache_dir!r}
  582. SOCK_DIR = {sock_dir!r}
  583. SRV_ROOT_DIR= {srv_root_dir!r}
  584. BASE_FILE_ROOTS_DIR = {base_file_roots_dir!r}
  585. BASE_PILLAR_ROOTS_DIR = {base_pillar_roots_dir!r}
  586. BASE_MASTER_ROOTS_DIR = {base_master_roots_dir!r}
  587. BASE_THORIUM_ROOTS_DIR = {base_thorium_roots_dir!r}
  588. LOGS_DIR = {logs_dir!r}
  589. PIDFILE_DIR = {pidfile_dir!r}
  590. SPM_PARENT_PATH = {spm_parent_path!r}
  591. SPM_FORMULA_PATH = {spm_formula_path!r}
  592. SPM_PILLAR_PATH = {spm_pillar_path!r}
  593. SPM_REACTOR_PATH = {spm_reactor_path!r}
  594. HOME_DIR = {home_dir!r}
  595. '''
  596. class Build(build):
  597. def run(self):
  598. # Run build.run function
  599. build.run(self)
  600. if getattr(self.distribution, 'with_salt_version', False):
  601. # Write the hardcoded salt version module salt/_version.py
  602. self.distribution.salt_version_hardcoded_path = os.path.join(
  603. self.build_lib, 'salt', '_version.py'
  604. )
  605. self.run_command('write_salt_version')
  606. if getattr(self.distribution, 'running_salt_install', False):
  607. # If our install attribute is present and set to True, we'll go
  608. # ahead and write our install time python modules.
  609. # Write the hardcoded salt version module salt/_version.py
  610. self.run_command('write_salt_version')
  611. # Write the system paths file
  612. self.distribution.salt_syspaths_hardcoded_path = os.path.join(
  613. self.build_lib, 'salt', '_syspaths.py'
  614. )
  615. self.run_command('generate_salt_syspaths')
  616. class Install(install):
  617. def initialize_options(self):
  618. install.initialize_options(self)
  619. def finalize_options(self):
  620. install.finalize_options(self)
  621. def run(self):
  622. # Let's set the running_salt_install attribute so we can add
  623. # _version.py in the build command
  624. self.distribution.running_salt_install = True
  625. self.distribution.salt_version_hardcoded_path = os.path.join(
  626. self.build_lib, 'salt', '_version.py'
  627. )
  628. if IS_WINDOWS_PLATFORM:
  629. # Download the required DLLs
  630. self.distribution.salt_download_windows_dlls = True
  631. self.run_command('download-windows-dlls')
  632. self.distribution.salt_download_windows_dlls = None
  633. # Run install.run
  634. install.run(self)
  635. class InstallLib(install_lib):
  636. def run(self):
  637. executables = [
  638. 'salt/templates/git/ssh-id-wrapper',
  639. 'salt/templates/lxc/salt_tarball',
  640. ]
  641. install_lib.run(self)
  642. # input and outputs match 1-1
  643. inp = self.get_inputs()
  644. out = self.get_outputs()
  645. chmod = []
  646. for idx, inputfile in enumerate(inp):
  647. for executable in executables:
  648. if inputfile.endswith(executable):
  649. chmod.append(idx)
  650. for idx in chmod:
  651. filename = out[idx]
  652. os.chmod(filename, 0o755)
  653. # <---- Custom Distutils/Setuptools Commands -------------------------------------------------------------------------
  654. # ----- Custom Distribution Class ----------------------------------------------------------------------------------->
  655. # We use this to override the package name in case --ssh-packaging is passed to
  656. # setup.py or the special .salt-ssh-package is found
  657. class SaltDistribution(distutils.dist.Distribution):
  658. '''
  659. Just so it's completely clear
  660. Under windows, the following scripts should be installed:
  661. * salt-call
  662. * salt-cp
  663. * salt-minion
  664. * salt-unity
  665. * salt-proxy
  666. When packaged for salt-ssh, the following scripts should be installed:
  667. * salt-call
  668. * salt-run
  669. * salt-ssh
  670. * salt-cloud
  671. Under windows, the following scripts should be omitted from the salt-ssh package:
  672. * salt-cloud
  673. * salt-run
  674. Under *nix, all scripts should be installed
  675. '''
  676. global_options = distutils.dist.Distribution.global_options + [
  677. ('ssh-packaging', None, 'Run in SSH packaging mode'),
  678. ('salt-transport=', None, 'The transport to prepare salt for. Currently, the only choice '
  679. 'is \'zeromq\'. This may be expanded in the future. Defaults to '
  680. '\'zeromq\'', 'zeromq')] + [
  681. ('with-salt-version=', None, 'Set a fixed version for Salt instead calculating it'),
  682. # Salt's Paths Configuration Settings
  683. ('salt-root-dir=', None,
  684. 'Salt\'s pre-configured root directory'),
  685. ('salt-share-dir=', None,
  686. 'Salt\'s pre-configured share directory'),
  687. ('salt-config-dir=', None,
  688. 'Salt\'s pre-configured configuration directory'),
  689. ('salt-cache-dir=', None,
  690. 'Salt\'s pre-configured cache directory'),
  691. ('salt-sock-dir=', None,
  692. 'Salt\'s pre-configured socket directory'),
  693. ('salt-srv-root-dir=', None,
  694. 'Salt\'s pre-configured service directory'),
  695. ('salt-base-file-roots-dir=', None,
  696. 'Salt\'s pre-configured file roots directory'),
  697. ('salt-base-pillar-roots-dir=', None,
  698. 'Salt\'s pre-configured pillar roots directory'),
  699. ('salt-base-master-roots-dir=', None,
  700. 'Salt\'s pre-configured master roots directory'),
  701. ('salt-logs-dir=', None,
  702. 'Salt\'s pre-configured logs directory'),
  703. ('salt-pidfile-dir=', None,
  704. 'Salt\'s pre-configured pidfiles directory'),
  705. ('salt-spm-formula-dir=', None,
  706. 'Salt\'s pre-configured SPM formulas directory'),
  707. ('salt-spm-pillar-dir=', None,
  708. 'Salt\'s pre-configured SPM pillar directory'),
  709. ('salt-spm-reactor-dir=', None,
  710. 'Salt\'s pre-configured SPM reactor directory'),
  711. ('salt-home-dir=', None,
  712. 'Salt\'s pre-configured user home directory'),
  713. ]
  714. def __init__(self, attrs=None):
  715. distutils.dist.Distribution.__init__(self, attrs)
  716. self.ssh_packaging = PACKAGED_FOR_SALT_SSH
  717. self.salt_transport = None
  718. # Salt Paths Configuration Settings
  719. self.salt_root_dir = None
  720. self.salt_share_dir = None
  721. self.salt_config_dir = None
  722. self.salt_cache_dir = None
  723. self.salt_sock_dir = None
  724. self.salt_srv_root_dir = None
  725. self.salt_base_file_roots_dir = None
  726. self.salt_base_thorium_roots_dir = None
  727. self.salt_base_pillar_roots_dir = None
  728. self.salt_base_master_roots_dir = None
  729. self.salt_logs_dir = None
  730. self.salt_pidfile_dir = None
  731. self.salt_spm_parent_dir = None
  732. self.salt_spm_formula_dir = None
  733. self.salt_spm_pillar_dir = None
  734. self.salt_spm_reactor_dir = None
  735. self.salt_home_dir = None
  736. # Salt version
  737. self.with_salt_version = None
  738. self.name = 'salt-ssh' if PACKAGED_FOR_SALT_SSH else 'salt'
  739. self.salt_version = __version__ # pylint: disable=undefined-variable
  740. self.description = 'Portable, distributed, remote execution and configuration management system'
  741. kwargs = {}
  742. if IS_PY3:
  743. kwargs['encoding'] = 'utf-8'
  744. with open(SALT_LONG_DESCRIPTION_FILE, **kwargs) as f:
  745. self.long_description = f.read()
  746. self.long_description_content_type = 'text/x-rst'
  747. self.author = 'Thomas S Hatch'
  748. self.author_email = 'thatch45@gmail.com'
  749. self.url = 'http://saltstack.org'
  750. self.cmdclass.update({'test': TestCommand,
  751. 'clean': Clean,
  752. 'build': Build,
  753. 'sdist': Sdist,
  754. 'install': Install,
  755. 'write_salt_version': WriteSaltVersion,
  756. 'generate_salt_syspaths': GenerateSaltSyspaths,
  757. 'write_salt_ssh_packaging_file': WriteSaltSshPackagingFile})
  758. if not IS_WINDOWS_PLATFORM:
  759. self.cmdclass.update({'sdist': CloudSdist,
  760. 'install_lib': InstallLib})
  761. if IS_WINDOWS_PLATFORM:
  762. self.cmdclass.update({'download-windows-dlls': DownloadWindowsDlls})
  763. if WITH_SETUPTOOLS:
  764. self.cmdclass.update({'develop': Develop})
  765. self.license = 'Apache Software License 2.0'
  766. self.packages = self.discover_packages()
  767. self.zip_safe = False
  768. if HAS_ESKY:
  769. self.setup_esky()
  770. self.update_metadata()
  771. def update_metadata(self):
  772. for attrname in dir(self):
  773. if attrname.startswith('__'):
  774. continue
  775. attrvalue = getattr(self, attrname, None)
  776. if attrvalue == 0:
  777. continue
  778. if attrname == 'salt_version':
  779. attrname = 'version'
  780. if hasattr(self.metadata, 'set_{0}'.format(attrname)):
  781. getattr(self.metadata, 'set_{0}'.format(attrname))(attrvalue)
  782. elif hasattr(self.metadata, attrname):
  783. try:
  784. setattr(self.metadata, attrname, attrvalue)
  785. except AttributeError:
  786. pass
  787. def discover_packages(self):
  788. modules = []
  789. for root, _, files in os.walk(os.path.join(SETUP_DIRNAME, 'salt')):
  790. if '__init__.py' not in files:
  791. continue
  792. modules.append(os.path.relpath(root, SETUP_DIRNAME).replace(os.sep, '.'))
  793. return modules
  794. # ----- Static Data -------------------------------------------------------------------------------------------->
  795. @property
  796. def _property_classifiers(self):
  797. return ['Programming Language :: Python',
  798. 'Programming Language :: Cython',
  799. 'Programming Language :: Python :: 2.6',
  800. 'Programming Language :: Python :: 2.7',
  801. 'Development Status :: 5 - Production/Stable',
  802. 'Environment :: Console',
  803. 'Intended Audience :: Developers',
  804. 'Intended Audience :: Information Technology',
  805. 'Intended Audience :: System Administrators',
  806. 'License :: OSI Approved :: Apache Software License',
  807. 'Operating System :: POSIX :: Linux',
  808. 'Topic :: System :: Clustering',
  809. 'Topic :: System :: Distributed Computing']
  810. @property
  811. def _property_dependency_links(self):
  812. return ['https://github.com/saltstack/salt-testing/tarball/develop#egg=SaltTesting']
  813. @property
  814. def _property_tests_require(self):
  815. return ['SaltTesting']
  816. # <---- Static Data ----------------------------------------------------------------------------------------------
  817. # ----- Dynamic Data -------------------------------------------------------------------------------------------->
  818. @property
  819. def _property_package_data(self):
  820. package_data = {'salt.templates': ['rh_ip/*.jinja',
  821. 'debian_ip/*.jinja',
  822. 'virt/*.jinja',
  823. 'git/*',
  824. 'lxc/*',
  825. ]}
  826. if not IS_WINDOWS_PLATFORM:
  827. package_data['salt.cloud'] = ['deploy/*.sh']
  828. if not self.ssh_packaging and not PACKAGED_FOR_SALT_SSH:
  829. package_data['salt.daemons.flo'] = ['*.flo']
  830. return package_data
  831. @property
  832. def _property_data_files(self):
  833. # Data files common to all scenarios
  834. data_files = [
  835. ('share/man/man1', ['doc/man/salt-call.1', 'doc/man/salt-run.1']),
  836. ('share/man/man7', ['doc/man/salt.7'])
  837. ]
  838. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  839. data_files[0][1].append('doc/man/salt-ssh.1')
  840. if IS_WINDOWS_PLATFORM:
  841. return data_files
  842. data_files[0][1].append('doc/man/salt-cloud.1')
  843. return data_files
  844. if IS_WINDOWS_PLATFORM:
  845. data_files[0][1].extend(['doc/man/salt-api.1',
  846. 'doc/man/salt-cp.1',
  847. 'doc/man/salt-key.1',
  848. 'doc/man/salt-master.1',
  849. 'doc/man/salt-minion.1',
  850. 'doc/man/salt-proxy.1',
  851. 'doc/man/salt-unity.1'])
  852. return data_files
  853. # *nix, so, we need all man pages
  854. data_files[0][1].extend(['doc/man/salt-api.1',
  855. 'doc/man/salt-cloud.1',
  856. 'doc/man/salt-cp.1',
  857. 'doc/man/salt-key.1',
  858. 'doc/man/salt-master.1',
  859. 'doc/man/salt-minion.1',
  860. 'doc/man/salt-proxy.1',
  861. 'doc/man/spm.1',
  862. 'doc/man/salt.1',
  863. 'doc/man/salt-ssh.1',
  864. 'doc/man/salt-syndic.1',
  865. 'doc/man/salt-unity.1'])
  866. return data_files
  867. @property
  868. def _property_install_requires(self):
  869. install_requires = _parse_requirements_file(SALT_REQS)
  870. if self.salt_transport == 'zeromq':
  871. install_requires += _parse_requirements_file(SALT_ZEROMQ_REQS)
  872. if IS_WINDOWS_PLATFORM:
  873. install_requires = _parse_requirements_file(SALT_WINDOWS_REQS)
  874. return install_requires
  875. @property
  876. def _property_scripts(self):
  877. # Scripts common to all scenarios
  878. scripts = ['scripts/salt-call', 'scripts/salt-run']
  879. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  880. scripts.append('scripts/salt-ssh')
  881. if IS_WINDOWS_PLATFORM:
  882. return scripts
  883. scripts.extend(['scripts/salt-cloud', 'scripts/spm'])
  884. return scripts
  885. if IS_WINDOWS_PLATFORM:
  886. scripts.extend(['scripts/salt',
  887. 'scripts/salt-api',
  888. 'scripts/salt-cp',
  889. 'scripts/salt-key',
  890. 'scripts/salt-master',
  891. 'scripts/salt-minion',
  892. 'scripts/salt-proxy',
  893. 'scripts/salt-unity'])
  894. return scripts
  895. # *nix, so, we need all scripts
  896. scripts.extend(['scripts/salt',
  897. 'scripts/salt-api',
  898. 'scripts/salt-cloud',
  899. 'scripts/salt-cp',
  900. 'scripts/salt-key',
  901. 'scripts/salt-master',
  902. 'scripts/salt-minion',
  903. 'scripts/salt-support',
  904. 'scripts/salt-ssh',
  905. 'scripts/salt-syndic',
  906. 'scripts/salt-unity',
  907. 'scripts/salt-proxy',
  908. 'scripts/spm'])
  909. return scripts
  910. @property
  911. def _property_entry_points(self):
  912. # console scripts common to all scenarios
  913. scripts = ['salt-call = salt.scripts:salt_call',
  914. 'salt-run = salt.scripts:salt_run']
  915. if self.ssh_packaging or PACKAGED_FOR_SALT_SSH:
  916. scripts.append('salt-ssh = salt.scripts:salt_ssh')
  917. if IS_WINDOWS_PLATFORM:
  918. return {'console_scripts': scripts}
  919. scripts.append('salt-cloud = salt.scripts:salt_cloud')
  920. return {'console_scripts': scripts}
  921. if IS_WINDOWS_PLATFORM:
  922. scripts.extend(['salt = salt.scripts:salt_main',
  923. 'salt-api = salt.scripts:salt_api',
  924. 'salt-cp = salt.scripts:salt_cp',
  925. 'salt-key = salt.scripts:salt_key',
  926. 'salt-master = salt.scripts:salt_master',
  927. 'salt-minion = salt.scripts:salt_minion',
  928. 'salt-unity = salt.scripts:salt_unity',
  929. 'spm = salt.scripts:salt_spm'])
  930. return {'console_scripts': scripts}
  931. # *nix, so, we need all scripts
  932. scripts.extend(['salt = salt.scripts:salt_main',
  933. 'salt-api = salt.scripts:salt_api',
  934. 'salt-cloud = salt.scripts:salt_cloud',
  935. 'salt-cp = salt.scripts:salt_cp',
  936. 'salt-key = salt.scripts:salt_key',
  937. 'salt-master = salt.scripts:salt_master',
  938. 'salt-minion = salt.scripts:salt_minion',
  939. 'salt-support = salt.scripts:salt_support',
  940. 'salt-ssh = salt.scripts:salt_ssh',
  941. 'salt-syndic = salt.scripts:salt_syndic',
  942. 'salt-unity = salt.scripts:salt_unity',
  943. 'spm = salt.scripts:salt_spm'])
  944. return {'console_scripts': scripts}
  945. # <---- Dynamic Data ---------------------------------------------------------------------------------------------
  946. # ----- Esky Setup ---------------------------------------------------------------------------------------------->
  947. def setup_esky(self):
  948. opt_dict = self.get_option_dict('bdist_esky')
  949. opt_dict['freezer_module'] = ('setup script', 'bbfreeze')
  950. opt_dict['freezer_options'] = ('setup script', {'includes': self.get_esky_freezer_includes()})
  951. @property
  952. def _property_freezer_options(self):
  953. return {'includes': self.get_esky_freezer_includes()}
  954. def get_esky_freezer_includes(self):
  955. # Sometimes the auto module traversal doesn't find everything, so we
  956. # explicitly add it. The auto dependency tracking especially does not work for
  957. # imports occurring in salt.modules, as they are loaded at salt runtime.
  958. # Specifying includes that don't exist doesn't appear to cause a freezing
  959. # error.
  960. freezer_includes = [
  961. 'zmq.core.*',
  962. 'zmq.utils.*',
  963. 'ast',
  964. 'csv',
  965. 'difflib',
  966. 'distutils',
  967. 'distutils.version',
  968. 'numbers',
  969. 'json',
  970. 'M2Crypto',
  971. 'Cookie',
  972. 'asyncore',
  973. 'fileinput',
  974. 'sqlite3',
  975. 'email',
  976. 'email.mime.*',
  977. 'requests',
  978. 'sqlite3',
  979. ]
  980. if HAS_ZMQ and hasattr(zmq, 'pyzmq_version_info'):
  981. if HAS_ZMQ and zmq.pyzmq_version_info() >= (0, 14):
  982. # We're freezing, and when freezing ZMQ needs to be installed, so this
  983. # works fine
  984. if 'zmq.core.*' in freezer_includes:
  985. # For PyZMQ >= 0.14, freezing does not need 'zmq.core.*'
  986. freezer_includes.remove('zmq.core.*')
  987. if IS_WINDOWS_PLATFORM:
  988. freezer_includes.extend([
  989. 'imp',
  990. 'win32api',
  991. 'win32file',
  992. 'win32con',
  993. 'win32com',
  994. 'win32net',
  995. 'win32netcon',
  996. 'win32gui',
  997. 'win32security',
  998. 'ntsecuritycon',
  999. 'pywintypes',
  1000. 'pythoncom',
  1001. '_winreg',
  1002. 'wmi',
  1003. 'site',
  1004. 'psutil',
  1005. 'pytz',
  1006. ])
  1007. elif IS_SMARTOS_PLATFORM:
  1008. # we have them as requirements in pkg/smartos/esky/requirements.txt
  1009. # all these should be safe to force include
  1010. freezer_includes.extend([
  1011. 'cherrypy',
  1012. 'python-dateutil',
  1013. 'pyghmi',
  1014. 'croniter',
  1015. 'mako',
  1016. 'gnupg',
  1017. ])
  1018. elif sys.platform.startswith('linux'):
  1019. freezer_includes.append('spwd')
  1020. try:
  1021. import yum # pylint: disable=unused-variable
  1022. freezer_includes.append('yum')
  1023. except ImportError:
  1024. pass
  1025. elif sys.platform.startswith('sunos'):
  1026. # (The sledgehammer approach)
  1027. # Just try to include everything
  1028. # (This may be a better way to generate freezer_includes generally)
  1029. try:
  1030. from bbfreeze.modulegraph.modulegraph import ModuleGraph
  1031. mgraph = ModuleGraph(sys.path[:])
  1032. for arg in glob.glob('salt/modules/*.py'):
  1033. mgraph.run_script(arg)
  1034. for mod in mgraph.flatten():
  1035. if type(mod).__name__ != 'Script' and mod.filename:
  1036. freezer_includes.append(str(os.path.basename(mod.identifier)))
  1037. except ImportError:
  1038. pass
  1039. return freezer_includes
  1040. # <---- Esky Setup -----------------------------------------------------------------------------------------------
  1041. # ----- Overridden Methods -------------------------------------------------------------------------------------->
  1042. def parse_command_line(self):
  1043. args = distutils.dist.Distribution.parse_command_line(self)
  1044. if not self.ssh_packaging and PACKAGED_FOR_SALT_SSH:
  1045. self.ssh_packaging = 1
  1046. if self.ssh_packaging:
  1047. self.metadata.name = 'salt-ssh'
  1048. self.salt_transport = 'ssh'
  1049. elif self.salt_transport is None:
  1050. self.salt_transport = 'zeromq'
  1051. if self.salt_transport not in ('zeromq', 'both', 'ssh', 'none'):
  1052. raise DistutilsArgError(
  1053. 'The value of --salt-transport needs be \'zeromq\', '
  1054. '\'both\', \'ssh\', or \'none\' not \'{0}\''.format(
  1055. self.salt_transport
  1056. )
  1057. )
  1058. # Setup our property functions after class initialization and
  1059. # after parsing the command line since most are set to None
  1060. # ATTENTION: This should be the last step before returning the args or
  1061. # some of the requirements won't be correctly set
  1062. for funcname in dir(self):
  1063. if not funcname.startswith('_property_'):
  1064. continue
  1065. property_name = funcname.split('_property_', 1)[-1]
  1066. setattr(self, property_name, getattr(self, funcname))
  1067. return args
  1068. # <---- Overridden Methods ---------------------------------------------------------------------------------------
  1069. # <---- Custom Distribution Class ------------------------------------------------------------------------------------
  1070. if __name__ == '__main__':
  1071. setup(distclass=SaltDistribution)