<commit_before># Android Device Testing Framework ("dtf")
# Copyright 2013-2015 <NAME> (@jake_valletta)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Python wrapper for Android tools"""

from dtf.globals import DTF_INCLUDED_DIR

from subprocess import Popen, PIPE

def aapt(cmd):

    """aapt wrapper"""

    aapt_path = "%s/aapt/aapt-22.0.1" % DTF_INCLUDED_DIR
    cmd = ("%s %s" % (aapt_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout = proc.stdout.read().split("\n")
    stderr = proc.stderr.read().split("\n")

    rtn = proc.wait()

    return stdout, stderr, rtn

def apktool(cmd):

    """apktool wrapper"""

    apktool_path = ("%s/apktool/apktool_2.0.3-83f327-SNAPSHOT.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, apktool_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout = proc.stdout.read().split("\n")
    stderr = proc.stderr.read().split("\n")

    rtn = proc.wait()

    return stdout, stderr, rtn

def smali(cmd):

    """smali wrapper"""

    smali_path = ("%s/smali/smali-2.1.0-3e265038.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, smali_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)
    stdout = proc.stdout.read().split("\n")
    stderr = proc.stderr.read().split("\n")

    rtn = proc.wait()

    return stdout, stderr, rtn

def baksmali(cmd):

    """baksmali wrapper"""

    baksmali_path = ("%s/smali/baksmali-2.1.0-3e265038.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, baksmali_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)
    stdout = proc.stdout.read().split("\n")
    stderr = proc.stderr.read().split("\n")

    rtn = proc.wait()

    return stdout, stderr, rtn

def dex2jar():

    """dex2jar wrapper"""

    raise NotImplementedError

def axmlprinter2(manifest_file_name, out_file_name):

    """axmlprinter2 wrapper"""

    axmlprinter2_path = ("%s/axmlprinter2/axmlprinter2.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx256M -jar"

    cmd = ("%s %s %s"
        % (java_args, axmlprinter2_path, manifest_file_name)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)
    stdout = proc.stdout.read()

    rtn = proc.wait()


    if len(stdout) == 0:
        return -1

    out_f = open(out_file_name, 'wb')

    try:
        out_f.write(stdout)
    finally:
        out_f.close()

    return rtn<commit_msg>Fixed deadlocks in included.py Using any of the included utilities (such as apktool()) could lead to a deadlock if too much stdout data is recieved. This has to do with issues in the subprocess function "wait()". I've changed this to now use "communicate()".<commit_after># Android Device Testing Framework ("dtf")
# Copyright 2013-2015 <NAME> (@jake_valletta)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Python wrapper for Android tools"""

from dtf.globals import DTF_INCLUDED_DIR

from subprocess import Popen, PIPE

def aapt(cmd):

    """aapt wrapper"""

    aapt_path = "%s/aapt/aapt-22.0.1" % DTF_INCLUDED_DIR
    cmd = ("%s %s" % (aapt_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout, stderr = proc.communicate()

    stdout = stdout.split("\n")
    stderr = stderr.split("\n")
    rtn = proc.returncode

    return stdout, stderr, rtn

def apktool(cmd):

    """apktool wrapper"""

    apktool_path = ("%s/apktool/apktool_2.0.3-83f327-SNAPSHOT.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, apktool_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout, stderr = proc.communicate()

    stdout = stdout.split("\n")
    stderr = stderr.split("\n")
    rtn = proc.returncode

    return stdout, stderr, rtn

def smali(cmd):

    """smali wrapper"""

    smali_path = ("%s/smali/smali-2.1.0-3e265038.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, smali_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout, stderr = proc.communicate()

    stdout = stdout.split("\n")
    stderr = stderr.split("\n")
    rtn = proc.returncode

    return stdout, stderr, rtn

def baksmali(cmd):

    """baksmali wrapper"""

    baksmali_path = ("%s/smali/baksmali-2.1.0-3e265038.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx512M -jar"

    cmd = ("%s %s %s" % (java_args, baksmali_path, cmd)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout, stderr = proc.communicate()

    stdout = stdout.split("\n")
    stderr = stderr.split("\n")
    rtn = proc.returncode

    return stdout, stderr, rtn

def dex2jar():

    """dex2jar wrapper"""

    raise NotImplementedError

def axmlprinter2(manifest_file_name, out_file_name):

    """axmlprinter2 wrapper"""

    axmlprinter2_path = ("%s/axmlprinter2/axmlprinter2.jar"
                        % DTF_INCLUDED_DIR)

    java_args = "java -Xmx256M -jar"

    cmd = ("%s %s %s"
        % (java_args, axmlprinter2_path, manifest_file_name)).split(' ')

    proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=False)

    stdout = proc.communicate()[0]

    rtn = proc.returncode

    if len(stdout) == 0:
        return -1

    out_f = open(out_file_name, 'wb')

    try:
        out_f.write(stdout)
    finally:
        out_f.close()

    return rtn
{'fraction_non_alphanumeric': 0.13912785523583507, 'fraction_numerical': 0.01972708395134975, 'mean_word_length': 2.9946682464454977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 12}, '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': '6469319', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2360, 'n_words': 605}