Skip to content

Commit

Permalink
more on logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Bachmann committed Nov 24, 2017
1 parent a4c264f commit ba64616
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion androguard/core/androconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@

log = logging.getLogger("androguard.default")


class InvalidResourceError(Exception):
"""
Invalid Resource Erorr is thrown by load_api_specific_resource_module
"""
pass


def is_ascii_problem(s):
"""
Test if a string contains other chars than ASCII
:param s: a string to test
:return: True if string contains other chars than ASCII, False otherwise
"""
try:
s.decode("ascii")
return False
Expand Down Expand Up @@ -92,6 +106,7 @@ class Color(object):
else:
CONF['data_prefix'] = os.path.join(sys.prefix, 'share', 'androguard')


def default_colors(obj):
CONF["COLORS"]["OFFSET"] = obj.Yellow
CONF["COLORS"]["OFFSET_ADDR"] = obj.Green
Expand Down Expand Up @@ -247,6 +262,8 @@ def show_logging(level=logging.INFO):
# Each class should use its own logger, so it is much easier to use.
def warning(x):
"""
DEPRECATED
Print out message x and the current traceback (if any)
:param x: String to be printed on stderr
Expand All @@ -259,6 +276,7 @@ def warning(x):

def error(x):
"""
DEPRECATED
Print out a message and raise an exception
TODO should this really raise an exception?
Expand All @@ -269,10 +287,22 @@ def error(x):


def debug(x):
"""
DEPRECATED
:param x:
:return:
"""
log.debug(x)


def info(x):
"""
DEPRECATED
:param x:
:return:
"""
log.info(x)


Expand All @@ -281,6 +311,11 @@ def set_options(key, value):


def rrmdir(directory):
"""
Recursivly delete a directory
:param directory: directory to remove
"""
for root, dirs, files in os.walk(directory, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
Expand Down Expand Up @@ -360,6 +395,7 @@ def color_range(startcolor, goalcolor, steps):

def load_api_specific_resource_module(resource_name, api):
# Those two imports are quite slow.
# Therefor we put them directly into this method
from androguard.core.api_specific_resources.aosp_permissions.aosp_permissions import AOSP_PERMISSIONS
from androguard.core.api_specific_resources.api_permission_mappings.api_permission_mappings import AOSP_PERMISSIONS_MAPPINGS

Expand All @@ -368,7 +404,7 @@ def load_api_specific_resource_module(resource_name, api):
elif resource_name == "api_permission_mappings":
mod = AOSP_PERMISSIONS_MAPPINGS
else:
error("Invalid resource: %s" % resource_name)
raise InvalidResourceError("Invalid Resource {}".format(resource_name))

if not api:
api = CONF["DEFAULT_API"]
Expand Down

0 comments on commit ba64616

Please sign in to comment.