updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / python-sphinx-breathe / setup.py
blobd3907602e27d22c134e82bada1750b8de19ab695
1 import os
2 import os.path
3 import sys
4 import shutil
6 def getpyver(cmd):
7 '''
8 Get python version
9 getpyver(python_path) --> python_version
11 Simple example:
12 getpyver("python3") --> "3.2"
13 '''
14 import subprocess
15 p = subprocess.Popen((cmd, "--version"), stderr=subprocess.PIPE)
16 if p.wait():
17 return None
18 p = p.stderr.read().decode('ascii')
19 p = p.split()[1].split('.')
20 return p[0] + '.' + p[1]
22 def get_python_path(cmd):
23 pyv = getpyver(cmd)
24 return ("/usr/lib/python{}/site-packages".format(pyv) if pyv else None)
26 def check(cmd):
27 path = get_python_path(cmd)
28 if os.path.isdir(os.path.join(path, "sphinx")):
29 return path
30 else:
31 return None
33 def copy_location():
34 if check("python3"):
35 return check("python3")
36 if check("python2"):
37 return check("python2")
38 raise RuntimeError("It seems that you have not install sphinx yet.")
40 pkgdir = sys.argv[1]
41 srcdir = sys.argv[2]
42 breathedir = os.path.join(srcdir, "breathe")
44 insdir = os.path.join(pkgdir, copy_location()[1:])
45 insdir = os.path.join(insdir, "breathe")
47 docdir = os.path.join(pkgdir, "usr/share/doc/python-sphinx-breathe")
48 htmldir = os.path.join(srcdir,"testsuite/build/html")
49 shutil.move(breathedir, insdir)
50 shutil.move(htmldir, docdir)