~harlowja/cloud-init/ds-openstack

« back to all changes in this revision

Viewing changes to tools/read-dependencies

  • Committer: Joshua Harlow
  • Date: 2014-02-07 23:14:26 UTC
  • mfrom: (913.1.22 trunk)
  • Revision ID: harlowja@yahoo-inc.com-20140207231426-2natgf64l4o055du
Remerged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
 
3
 
set -e
4
 
 
5
 
find_root() {
6
 
   local topd
7
 
   if [ -z "${CLOUD_INIT_TOP_D}" ]; then
8
 
      topd=$(cd "$(dirname "${0}")" && cd .. && pwd)
9
 
   else
10
 
      topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd)
11
 
   fi
12
 
   [ $? -eq 0 -a -f "${topd}/setup.py" ] || return
13
 
   ROOT_DIR="$topd"
14
 
}
15
 
fail() { echo "$0:" "$@" 1>&2; exit 1; }
16
 
 
17
 
if ! find_root; then
18
 
    fail "Unable to locate 'setup.py' file that should " \
19
 
         "exist in the cloud-init root directory."
20
 
fi
21
 
 
22
 
REQUIRES="$ROOT_DIR/requirements.txt"
23
 
 
24
 
if [ ! -e "$REQUIRES" ]; then
25
 
    fail "Unable to find 'requirements.txt' file located at '$REQUIRES'"
26
 
fi
27
 
 
28
 
# Filter out comments and empty lines
29
 
DEPS=$(sed -n -e 's,#.*,,' -e '/./p' "$REQUIRES") &&
30
 
   [ -n "$DEPS" ] ||
31
 
   fail "failed to read deps from '${REQUIRES}'"
32
 
echo "$DEPS" | sort -d -f
 
1
#!/usr/bin/env python
 
2
 
 
3
import os
 
4
import sys
 
5
 
 
6
if 'CLOUD_INIT_TOP_D' in os.environ:
 
7
    topd = os.path.realpath(os.environ.get('CLOUD_INIT_TOP_D'))
 
8
else:
 
9
    topd = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
 
10
 
 
11
for fname in ("setup.py", "requirements.txt"):
 
12
    if not os.path.isfile(os.path.join(topd, fname)):
 
13
        sys.stderr.write("Unable to locate '%s' file that should "
 
14
                         "exist in cloud-init root directory." % fname)
 
15
        sys.exit(1)
 
16
 
 
17
with open(os.path.join(topd, "requirements.txt"), "r") as fp:
 
18
    for line in fp:
 
19
        if not line.strip() or line.startswith("#"):
 
20
            continue
 
21
        sys.stdout.write(line)
 
22
 
 
23
sys.exit(0)