<commit_before>#!/usr/bin/env python
"""
to install latest release nova-agent from GitHub
$ ./install_agent.py

to install a specific release version from GitHub
$ ./install_agent.py --version <XX.YY.ZZ.NN>

to install a specific release version from another absolute URL
$ ./install_agent.py --url <http://URL>

to install a specific release version from already uploaded TGZ
$ ./install_agent.py --local <local/path>
"""

import os
import sys
import subprocess
import shutil
import time
import platform
import json
import urllib2

distro_name = platform.dist()[0]
distro_family = platform.system()


def panic(msg):
    """ To do suitable task on PANIC state, Exit and Call for help. """
    print(msg)
    sys.exit(1)


def run_me_right(cmd):
    """ Run what is asked for and Panic if it fails. """
    print("Running: %s" % cmd)
    statuscode = subprocess.call(cmd.split())
    if statuscode != 0:
        panic("FAILURE: %s" % cmd)


def latest_github_tag():
    """ Returns latest Release Tag at GitHub. """
    release_tags_github_url = "https://api.github.com/repos/rackerlabs/openstack-guest-agents-unix/tags"
    release_tags_json = urllib2.urlopen(release_tags_github_url)
    release_tags_data = json.load(release_tags_json)
    return str(release_tags_data[0]['name'])[1:]


def download_link(link, to_file=""):
    """ Curls down the link to a specific filename if provided or default. """
    if to_file:
        switch = "--create-dirs -skLo"
    else:
        switch = "-skL"
    run_me_right("curl %s %s %s" % (switch, to_file, link))


def install_uuid():
    """ Installing UUID package for Testing purpose. """
    version = "1.30"
    base_path = "/tmp/uuid"
    if os.path.exists(path):
        run_me_right("%s stop" % base_path)

    tar_name = "uuid-%s.tar.gz" % (version)
    tar_path = "%s/%s" % (base_path, tar_name)<commit_msg>[tests][install-agent] json usage made optional to suit distros with Py2.4<commit_after>#!/usr/bin/env python
"""
to install latest release nova-agent from GitHub
$ ./install_agent.py

to install a specific release version from GitHub
$ ./install_agent.py --version <XX.YY.ZZ.NN>

to install a specific release version from another absolute URL
$ ./install_agent.py --url <http://URL>

to install a specific release version from already uploaded TGZ
$ ./install_agent.py --local <local/path>
"""

import os
import sys
import subprocess
import shutil
import time
import platform
import urllib2

distro_name = platform.dist()[0]
distro_family = platform.system()


def panic(msg):
    """ To do suitable task on PANIC state, Exit and Call for help. """
    print(msg)
    sys.exit(1)


def run_me_right(cmd):
    """ Run what is asked for and Panic if it fails. """
    print("Running: %s" % cmd)
    statuscode = subprocess.call(cmd.split())
    if statuscode != 0:
        panic("FAILURE: %s" % cmd)


def latest_github_tag():
    """ Returns latest Release Tag at GitHub. """
    release_tag = os.getenv("NOVA_AGENT_RELEASE")
    if release_tag:
        return release_tag

    import json
    release_tags_github_url = "https://api.github.com/repos/rackerlabs/openstack-guest-agents-unix/tags"
    release_tags_json = urllib2.urlopen(release_tags_github_url)
    release_tags_data = json.load(release_tags_json)
    return str(release_tags_data[0]['name'])[1:]


def download_link(link, to_file=""):
    """ Curls down the link to a specific filename if provided or default. """
    if to_file:
        switch = "--create-dirs -skLo"
    else:
        switch = "-skL"
    run_me_right("curl %s %s %s" % (switch, to_file, link))


def install_uuid():
    """ Installing UUID package for Testing purpose. """
    version = "1.30"
    base_path = "/tmp/uuid"
    if os.path.exists(path):
        run_me_right("%s stop" % base_path)

    tar_name = "uuid-%s.tar.gz" % (version)
    tar_path = "%s/%s" % (base_path, tar_name)
{'fraction_non_alphanumeric': 0.1285751095078588, 'fraction_numerical': 0.0056686421025508886, 'mean_word_length': 3.4982618771726535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6254846', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1262, 'n_words': 366}