summaryrefslogtreecommitdiff
path: root/tools/read-dependencies
blob: 9fc503ebccfd780fa4e3af08a605747bfd5e36c4 (plain)
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
#!/usr/bin/env python

# You might be tempted to rewrite this as a shell script, but you
# would be surprised to discover that things like 'egrep' or 'sed' may
# differ between Linux and *BSD.

import os
import re
import sys
import subprocess

if 'CLOUD_INIT_TOP_D' in os.environ:
    topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
else:
    topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

for fname in ("setup.py", "requirements.txt"):
    if not os.path.isfile(os.path.join(topd, fname)):
        sys.stderr.write("Unable to locate '%s' file that should "
                         "exist in cloud-init root directory." % fname)
        sys.exit(1)

if len(sys.argv) > 1:
    reqfile = sys.argv[1]
else:
    reqfile = "requirements.txt"

with open(os.path.join(topd, reqfile), "r") as fp:
    for line in fp:
        line = line.strip()
        if not line or line.startswith("#"):
            continue

        # remove pip-style markers
        dep = line.split(';')[0]

        # remove version requirements
        dep = re.split("[>=.<]*", dep)[0].strip()
        print(dep)

sys.exit(0)