From 1206082bdf0a25a2675296c01cf798e4da835d1b Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 29 Oct 2014 12:50:57 -0300 Subject: Add code to specify tuf stable/unstable. --- bitmask-0.7.0rc3.json | 1 + bundler/actions.py | 14 +++++++++++--- bundler/main.py | 37 +++++++++++++++++++++++++++---------- tuf-stuff.sh | 27 ++++++++++++++++++++++++--- 4 files changed, 63 insertions(+), 16 deletions(-) diff --git a/bitmask-0.7.0rc3.json b/bitmask-0.7.0rc3.json index 8112108..70559c8 100644 --- a/bitmask-0.7.0rc3.json +++ b/bitmask-0.7.0rc3.json @@ -1,5 +1,6 @@ { "version": "0.7.0rc3", + "tuf_repo": "unstable", "bitmask_client": "0.7.0rc3", "soledad": "0.6.0", "leap_pycommon": "0.3.9", diff --git a/bundler/actions.py b/bundler/actions.py index 883aaac..1f688e3 100644 --- a/bundler/actions.py +++ b/bundler/actions.py @@ -517,13 +517,15 @@ class CopyMisc(Action): updater_delay = 60 [Mirror.localhost] - url_prefix = http://dl.bitmask.net/tuf""") + url_prefix = {0}""") + TUF_STABLE = "https://dl.bitmask.net/tuf" + TUF_UNSTABLE = "https://dl.bitmask.net/tuf-unstable" def __init__(self, basedir, skip, do): Action.__init__(self, "copymisc", basedir, skip, do) @skippable - def run(self, binary_path): + def run(self, binary_path, tuf_repo): self.log("downloading thunderbird extension...") ext_path = platform_dir(self._basedir, "apps", "bitmask-thunderbird-latest.xpi") @@ -560,8 +562,14 @@ class CopyMisc(Action): _convert_path_for_win(os.path.join(self._basedir, "Bitmask"))) launcher_path = os.path.join(self._basedir, "Bitmask", "launcher.conf") + + if tuf_repo == 'stable': + tuf_config = self.TUF_CONFIG.format(self.TUF_STABLE) + elif tuf_repo == 'unstable': + tuf_config = self.TUF_CONFIG.format(self.TUF_UNSTABLE) + with open(launcher_path, "w") as f: - f.write(self.TUF_CONFIG) + f.write(tuf_config) metadata = os.path.join(self._basedir, "Bitmask", "repo", "metadata") mkdir("-p", os.path.join(metadata, "current")) diff --git a/bundler/main.py b/bundler/main.py index 234a1ba..733a241 100644 --- a/bundler/main.py +++ b/bundler/main.py @@ -41,6 +41,19 @@ def new_build_dir(default=None): dir_util.remove_tree(bd) +def _get_dict_from_json(json_file): + data = {} + + try: + with open(json_file, 'r') as f: + data = json.load(f) + except Exception as e: + print "Problem loading json: {0!r}".format(e) + pass + + return data + + def get_version(versions_file): """ Return the "version" data on the json file given as parameter. @@ -50,17 +63,21 @@ def get_version(versions_file): :rtype: str or None """ - version = None - try: - versions = None - with open(versions_file, 'r') as f: - versions = json.load(f) + versions = _get_dict_from_json(versions_file) + return versions.get('version') - version = versions.get("version") - except Exception as e: - print "Problem getting version: {0!r}".format(e) - return version +def get_tuf_repo(versions_file): + """ + Return the "tuf_repo" data on the json file given as parameter. + + :param versions_file: the file name of the json to parse. + :type versions_file: str + + :rtype: str or None + """ + versions = _get_dict_from_json(versions_file) + return versions.get('tuf_repo') def main(): @@ -132,7 +149,7 @@ def main(): fd.run() cm = init(CopyMisc) - cm.run(binaries_path) + cm.run(binaries_path, get_tuf_repo(versions_path)) pyc = init(PycRemover) pyc.run() diff --git a/tuf-stuff.sh b/tuf-stuff.sh index 63c215f..b8de3f3 100755 --- a/tuf-stuff.sh +++ b/tuf-stuff.sh @@ -35,7 +35,7 @@ cc_normal="${esc}[39m" show_help() { cat << EOF -Usage: ${0##*/} [-h] [-r FILE] [-s] [-a (32|64)] -v VERSION -k KEY_FILE +Usage: ${0##*/} [-h] [-r FILE] [-s] [-a (32|64)] -v VERSION -k KEY_FILE -R (S|U) Do stuff for version VERSION and arch ARCH. -h display this help and exit. @@ -44,6 +44,7 @@ Do stuff for version VERSION and arch ARCH. -r FILE use particular repo/ file to do the tuf stuff. FILE must be a .tar.gz file. -s run the setup process, create virtualenv and install dependencies. -v VERSION version to work with. This is a mandatory argument. + -R REPO use the (S)table or (U)nstable TUF web repo. EOF } @@ -54,7 +55,7 @@ get_args() { ARCH="64" SETUP="NO" - while getopts "hr:sv:a:k:" opt; do + while getopts "hr:sv:a:k:R:" opt; do case "$opt" in h) show_help @@ -70,6 +71,8 @@ get_args() { ;; a) ARCH=$OPTARG ;; + R) WEB_REPO=$OPTARG + ;; '?') show_help >&2 exit 1 @@ -88,6 +91,17 @@ get_args() { show_help exit 1 fi + if [[ -z $WEB_REPO ]]; then + echo 'Error: missing -R flag' + show_help + exit 1 + else + if [[ $WEB_REPO != 'S' && $WEB_REPO != 'U' ]]; then + echo 'Error: invalid parameter for the -R flag' + show_help + exit 2 + fi + fi echo "---------- settings ----------" echo "Arch: $ARCH" @@ -95,6 +109,7 @@ get_args() { echo "Repo: $REPO" echo "Setup: $SETUP" echo "Version: $VERSION" + echo "Web repo: $WEB_REPO" echo "--------------------" read -p "Press to continue, +C to exit. " } @@ -149,10 +164,16 @@ do_tuf_stuff() { TUF_ARCH='linux-i386' fi + if [[ $WEB_REPO == 'S' ]]; then + TUF_URL=https://dl.bitmask.net/tuf/$TUF_ARCH/metadata/ + else + TUF_URL=https://dl.bitmask.net/tuf-unstable/$TUF_ARCH/metadata/ + fi + if [[ -z $REPO ]]; then # Download old repo metadata echo "${cc_yellow}-> Downloading metadata files from the old bundle...${cc_normal}" - wget --quiet --recursive --no-host-directories --cut-dirs=2 --no-parent --reject "index.html*" https://dl.bitmask.net/tuf/$TUF_ARCH/metadata/ + wget --quiet --recursive --no-host-directories --cut-dirs=2 --no-parent --reject "index.html*" $TUF_URL mv metadata metadata.staged else echo "${cc_yellow}-> Extracting metadata files from the repo file...${cc_normal}" -- cgit v1.2.3