summaryrefslogtreecommitdiff
path: root/tools/read-dependencies
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-02-07 15:14:26 -0800
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-02-07 15:14:26 -0800
commit2983a26ecf9716dc957ec4bacf15544072774190 (patch)
treea7e074c21789ebc553713b3fd591fd9bbe4a9684 /tools/read-dependencies
parent810df2c55c108e7e4064263e508d9786d8b1dc8e (diff)
parent3cfe9b3d8958b1a4e450d5ff31d805c424945027 (diff)
downloadvyos-cloud-init-2983a26ecf9716dc957ec4bacf15544072774190.tar.gz
vyos-cloud-init-2983a26ecf9716dc957ec4bacf15544072774190.zip
Remerged with trunk
Diffstat (limited to 'tools/read-dependencies')
-rwxr-xr-xtools/read-dependencies45
1 files changed, 18 insertions, 27 deletions
diff --git a/tools/read-dependencies b/tools/read-dependencies
index f89391bc..fee3efcf 100755
--- a/tools/read-dependencies
+++ b/tools/read-dependencies
@@ -1,32 +1,23 @@
-#!/bin/sh
+#!/usr/bin/env python
-set -e
+import os
+import sys
-find_root() {
- local topd
- if [ -z "${CLOUD_INIT_TOP_D}" ]; then
- topd=$(cd "$(dirname "${0}")" && cd .. && pwd)
- else
- topd=$(cd "${CLOUD_INIT_TOP_D}" && pwd)
- fi
- [ $? -eq 0 -a -f "${topd}/setup.py" ] || return
- ROOT_DIR="$topd"
-}
-fail() { echo "$0:" "$@" 1>&2; exit 1; }
+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__)))
-if ! find_root; then
- fail "Unable to locate 'setup.py' file that should " \
- "exist in the cloud-init root directory."
-fi
+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)
-REQUIRES="$ROOT_DIR/requirements.txt"
+with open(os.path.join(topd, "requirements.txt"), "r") as fp:
+ for line in fp:
+ if not line.strip() or line.startswith("#"):
+ continue
+ sys.stdout.write(line)
-if [ ! -e "$REQUIRES" ]; then
- fail "Unable to find 'requirements.txt' file located at '$REQUIRES'"
-fi
-
-# Filter out comments and empty lines
-DEPS=$(sed -n -e 's,#.*,,' -e '/./p' "$REQUIRES") &&
- [ -n "$DEPS" ] ||
- fail "failed to read deps from '${REQUIRES}'"
-echo "$DEPS" | sort -d -f
+sys.exit(0)