daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Apr 25th, 2017 281 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python2.7
  2.  
  3. import traceback
  4. import os
  5. import sys
  6. try:
  7.     from setuptools import setup, Extension
  8.     haveSetuptools = True
  9. except ImportError:
  10.     haveSetuptools = False
  11.  
  12. from importlib import import_module
  13.  
  14. from src.version import softwareVersion
  15.  
  16. packageManager = {
  17.     "OpenBSD": "pkg_add",
  18.     "FreeBSD": "pkg install",
  19.     "Debian": "apt-get install",
  20.     "Ubuntu": "apt-get install",
  21.     "openSUSE": "zypper install",
  22.     "Fedora": "dnf install",
  23.     "Guix": "guix package -i",
  24.     "Gentoo": "emerge"
  25. }
  26.  
  27. packageName = {
  28.     "PyQt4": {
  29.         "OpenBSD": "py-qt4",
  30.         "FreeBSD": "py27-qt4",
  31.         "Debian": "python-qt4",
  32.         "Ubuntu": "python-qt4",
  33.         "openSUSE": "python-qt",
  34.         "Fedora": "PyQt4",
  35.         "Guix": "python2-pyqt@4.11.4",
  36.         "Gentoo": "dev-python/PyQt4",
  37.         'optional': True,
  38.         'description': "You only need PyQt if you want to use the GUI. " \
  39.             "When only running as a daemon, this can be skipped.\n" \
  40.             "However, you would have to install it manually " \
  41.             "because setuptools does not support PyQt."
  42.     },
  43.     "msgpack": {
  44.         "OpenBSD": "py-msgpack",
  45.         "FreeBSD": "py27-msgpack-python",
  46.         "Debian": "python-msgpack",
  47.         "Ubuntu": "python-msgpack",
  48.         "openSUSE": "python-msgpack-python",
  49.         "Fedora": "python2-msgpack",
  50.         "Guix": "python2-msgpack",
  51.         "Gentoo": "dev-python/msgpack"
  52.     },
  53.     "pyopencl": {
  54.         "FreeBSD": "py27-pyopencl",
  55.         "Debian": "python-pyopencl",
  56.         "Ubuntu": "python-pyopencl",
  57.         "Fedora": "python2-pyopencl",
  58.         "openSUSE": "",
  59.         "OpenBSD": "",
  60.         "Guix": "",
  61.         "Gentoo": "dev-python/pyopencl",
  62.         "optional": True,
  63.         'description': "If you install pyopencl, you will be able to use " \
  64.             "GPU acceleration for proof of work. \n" \
  65.             "You also need a compatible GPU and drivers."
  66.     },
  67.     "setuptools": {
  68.         "OpenBSD": "py-setuptools",
  69.         "FreeBSD": "py27-setuptools",
  70.         "Debian": "python-setuptools",
  71.         "Ubuntu": "python-setuptools",
  72.         "Fedora": "python2-setuptools",
  73.         "openSUSE": "python-setuptools",
  74.         "Guix": "python2-setuptools",
  75.         "Gentoo": "",
  76.     }
  77. }
  78.  
  79. compiling = {
  80.         "Debian": "build-essential libssl-dev",
  81.         "Ubuntu": "build-essential libssl-dev",
  82.         "Fedora": "gcc-c++ redhat-rpm-config python-devel openssl-devel",
  83.         "openSUSE": "gcc-c++ libopenssl-devel python-devel",
  84. }
  85.  
  86.  
  87. def detectOS():
  88.     if detectOS.result is not None:
  89.         return detectOS.result
  90.     if sys.platform.startswith('openbsd'):
  91.         detectOS.result = "OpenBSD"
  92.     elif sys.platform.startswith('freebsd'):
  93.         detectOS.result = "FreeBSD"
  94.     elif sys.platform.startswith('win'):
  95.         detectOS.result = "Windows"
  96.     elif os.path.isfile("/etc/os-release"):
  97.         with open("/etc/os-release", 'rt') as osRelease:
  98.             for line in osRelease:
  99.                 if line.startswith("NAME="):
  100.                     line = line.lower()
  101.                     if "fedora" in line:
  102.                         detectOS.result = "Fedora"
  103.                     elif "opensuse" in line:
  104.                         detectOS.result = "openSUSE"
  105.                     elif "ubuntu" in line:
  106.                         detectOS.result = "Ubuntu"
  107.                     elif "debian" in line:
  108.                         detectOS.result = "Debian"
  109.                     elif "gentoo" in line or "calculate" in line:
  110.                         detectOS.result = "Gentoo"
  111.                     else:
  112.                         detectOS.result = None
  113.     elif os.path.isfile("/etc/config.scm"):
  114.         detectOS.result = "Guix"
  115.     return detectOS.result
  116.  
  117.  
  118. def detectPrereqs(missing=False):
  119.     available = []
  120.     for module in packageName.keys():
  121.         try:
  122.             import_module(module)
  123.             if not missing:
  124.                 available.append(module)
  125.         except ImportError:
  126.             if missing:
  127.                 available.append(module)
  128.     return available
  129.  
  130.  
  131. def prereqToPackages():
  132.     print "You can install the requirements by running, as root:"
  133.     print "%s %s" % (
  134.         packageManager[detectOS()], " ".join(
  135.             packageName[x][detectOS()] for x in detectPrereqs(True)))
  136.     for package in detectPrereqs(True):
  137.         if packageName[package]['optional']:
  138.             print packageName[package]['description']
  139.  
  140. def compilerToPackages():
  141.     if not detectOS() in compiling:
  142.         return
  143.     print "You can install the requirements by running, as root:"
  144.     print "%s %s" % (
  145.         packageManager[detectOS()], compiling[detectOS()])
  146.  
  147. if __name__ == "__main__":
  148.     detectOS.result = None
  149.     detectPrereqs.result = None
  150.     if detectPrereqs(True) != [] and detectOS() in packageManager:
  151.         if detectOS() is not None:
  152.             print "It looks like you're using %s. " \
  153.                 "It is highly recommended to use the package manager " \
  154.                 "instead of setuptools." % (detectOS())
  155.             prereqToPackages()
  156.             for module in detectPrereqs(True):
  157.                 if not packageName[module]['optional']:
  158.                     print module
  159.                     sys.exit()
  160.     if not haveSetuptools:
  161.         print "It looks like you're missing setuptools."
  162.         sys.exit()
  163.  
  164.     if detectPrereqs(True) != []:
  165.         print "Press Return to continue"
  166.         try:
  167.             nothing = raw_input()
  168.         except NameError:
  169.             pass
  170.  
  171.     here = os.path.abspath(os.path.dirname(__file__))
  172.     with open(os.path.join(here, 'README.md')) as f:
  173.         README = f.read()
  174.  
  175.     bitmsghash = Extension(
  176.         'pybitmessage.bitmsghash.bitmsghash',
  177.         sources=['src/bitmsghash/bitmsghash.cpp'],
  178.         libraries=['pthread', 'crypto'],
  179.     )
  180.  
  181.     try:
  182.         dist = setup(
  183.             name='pybitmessage',
  184.             version=softwareVersion,
  185.             description="Reference client for Bitmessage: "
  186.             "a P2P communications protocol",
  187.             long_description=README,
  188.             license='MIT',
  189.             # TODO: add author info
  190.             #author='',
  191.             #author_email='',
  192.             url='https://bitmessage.org',
  193.             # TODO: add keywords
  194.             #keywords='',
  195.             install_requires=['msgpack-python'],
  196.             classifiers=[
  197.                 "License :: OSI Approved :: MIT License"
  198.                 "Operating System :: OS Independent",
  199.                 "Programming Language :: Python :: 2.7 :: Only",
  200.                 "Topic :: Internet",
  201.                 "Topic :: Security :: Cryptography",
  202.                 "Topic :: Software Development :: Libraries :: Python Modules",
  203.             ],
  204.             package_dir={'pybitmessage': 'src'},
  205.             packages=[
  206.                 'pybitmessage',
  207.                 'pybitmessage.bitmessageqt',
  208.                 'pybitmessage.bitmessagecurses',
  209.                 'pybitmessage.messagetypes',
  210.                 'pybitmessage.network',
  211.                 'pybitmessage.pyelliptic',
  212.                 'pybitmessage.socks',
  213.             ],
  214.             package_data={'': [
  215.                 'bitmessageqt/*.ui', 'bitmsghash/*.cl', 'sslkeys/*.pem',
  216.                 'translations/*.ts', 'translations/*.qm',
  217.                 'images/*.png', 'images/*.ico', 'images/*.icns'
  218.             ]},
  219.             ext_modules=[bitmsghash],
  220.             zip_safe=False,
  221.             #entry_points={
  222.             #    'console_scripts': [
  223.             #        'pybitmessage = pybitmessage.bitmessagemain:main'
  224.             #    ]
  225.             #},
  226.             scripts=['src/pybitmessage']
  227.         )
  228.     except SystemExit:
  229.     traceback.print_exc()
  230.     print "It looks like building the package failed.\n" \
  231.             "You may be missing a C++ compiler and the OpenSSL headers."
  232.         compilerToPackages()
RAW Paste Data
Top