<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Badit (BuildAndDebugIT) is a program to to simplify the process of deployment
and updating an android project
 copyright:  2012, (c) tuenti.com
 author:   <NAME> <<EMAIL>>
"""
import sys
import getopt
import os
import subprocess
# import getpass
import logging
# import pprint

build_bit =     (1 << 0)
uninstall_bit = (1 << 1)
install_bit =   (1 << 2)
start_bit =     (1 << 3)
debug_bit =     (1 << 4)

#global vars
taskMask = build_bit | install_bit | start_bit | debug_bit
profile = "default_debug"
supportedProfiles = ["default_debug", "default_release", "default_final",
                     "tuenti_debug", "tuenti_release", "tuenti_final"]
supportedNDKs = ["r8", "r8d"]

##
##  The following options are provided.
##  --help [-h]. What you are reading now
##  --log-level [-l]. setting the log level dynamically
##  --profile [-p]. Setting build profile
##  --task-mask [-m]. skip over some tasks
##  --build [-b] build. Build the apk
##  --uninstall [-u] uninstall. Uninstall the apk
##  --install [-i] install. Install the apk
##  --start [-s] start. Start the apk
##  --debug [-d] debug. Debug the apk

logger = logging.getLogger(__name__)


def usage():
    fh = open(__file__, "r")
    me = fh.readlines()
    sys.stderr.write("usage:\n")
    for line in me:
        if line.find("##") == 0:
            sys.stderr.write(line)


def runCmd(name, cmdList):
    logger.info("=> " + name + " = " + " ".join(cmdList))
    if subprocess.call(cmdList) == 0:
        logger.info("[OK] " + name + " = " + " ".join(cmdList))
    else:
        logger.error("[KO] " + name + " = " + " ".join(cmdList))
        return 1
    return 0


def mavenBuild():
    if taskMask & build_bit:
        if profile not in supportedProfiles:
            logger.error("[KO] Build bad profile " + profile + "\noptions are: " + ", ".join(supportedProfiles) + "\nexiting.")
            sys.exit(1)
        if runCmd("Build", ["mvn", "install", "--activate-profiles", profile]) != 0:
            sys.exit(1)
    else:
        logger.info("skipping build")


def uninstallApk():
    if taskMask & uninstall_bit:
        # we don't want to fail during the uninstall
        runCmd("Uninstall", ["adb", "uninstall", "com.tuenti.voice.example"])
    else:
        logger.info("skipping uninstall")


def installApk():
    if taskMask & install_bit:<commit_msg>verify that all executables that we are running exist<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Badit (BuildAndDebugIT) is a program to to simplify the process of deployment
and updating an android project
 copyright:  2012, (c) tuenti.com
 author:   <NAME> <<EMAIL>>
"""
import sys
import getopt
import os
import subprocess
# import getpass
import logging
# import pprint

build_bit =     (1 << 0)
uninstall_bit = (1 << 1)
install_bit =   (1 << 2)
start_bit =     (1 << 3)
debug_bit =     (1 << 4)

#global vars
taskMask = build_bit | install_bit | start_bit | debug_bit
profile = "default_debug"
supportedProfiles = ["default_debug", "default_release", "default_final",
                     "tuenti_debug", "tuenti_release", "tuenti_final"]
supportedNDKs = ["r8", "r8d"]

##
##  The following options are provided.
##  --help [-h]. What you are reading now
##  --log-level [-l]. setting the log level dynamically
##  --profile [-p]. Setting build profile
##  --task-mask [-m]. skip over some tasks
##  --build [-b] build. Build the apk
##  --uninstall [-u] uninstall. Uninstall the apk
##  --install [-i] install. Install the apk
##  --start [-s] start. Start the apk
##  --debug [-d] debug. Debug the apk

logger = logging.getLogger(__name__)


def usage():
    fh = open(__file__, "r")
    me = fh.readlines()
    sys.stderr.write("usage:\n")
    for line in me:
        if line.find("##") == 0:
            sys.stderr.write(line)

def which(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None

def runCmd(name, cmdList):
    logger.info("=> " + name + " = " + " ".join(cmdList))
    if which(cmdList[0]) == None:
        logger.info("[KO] [" + cmdList[0] + "] command doesn't exist you must install it")
        return 1
    if subprocess.call(cmdList) == 0:
        logger.info("[OK] " + name + " = " + " ".join(cmdList))
    else:
        logger.error("[KO] " + name + " = " + " ".join(cmdList))
        return 1
    return 0


def mavenBuild():
    if taskMask & build_bit:
        if profile not in supportedProfiles:
            logger.error("[KO] Build bad profile " + profile + "\noptions are: " + ", ".join(supportedProfiles) + "\nexiting.")
            sys.exit(1)
        if runCmd("Build", ["mvn", "install", "--activate-profiles", profile]) != 0:
            sys.exit(1)
    else:
        logger.info("skipping build")


def uninstallApk():
    if taskMask & uninstall_bit:
        # we don't want to fail during the uninstall
        runCmd("Uninstall", ["adb", "uninstall", "com.tuenti.voice.example"])
    else:
        logger.info("skipping uninstall")


def installApk():
    if taskMask & install_bit:
{'fraction_non_alphanumeric': 0.15527379639838296, 'fraction_numerical': 0.009371554575523704, 'mean_word_length': 2.7229822161422708, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589022', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1762, 'n_words': 515}