androlyze.util package¶
Submodules¶
androlyze.util.CLIUtil module¶
-
exception
androlyze.util.CLIUtil.
CLIError
(msg, argparser=None)[source]¶ Bases:
androlyze.error.AndroLyzeLabError.AndroLyzeLabError
Generic exception to raise and log different fatal errors and print the help menu afterwards
-
androlyze.util.CLIUtil.
cli_check_n_exec
(func, prompt_prefix='', circumvent_check=False, args=(), kwargs={})[source]¶ Check if the user really want’s to continue and exec func. Otherwise quit the program with exit code 1 and log some message.
Returns the result of the func or None.
-
androlyze.util.CLIUtil.
get_basic_result_query_options
(args)[source]¶ Get basic result query optionsfor result db from run and build kwargs for
ResultDatabaseStorage.get_results()
. Also see :py:method:`.androlyze.setup_basic_result_query_options` for the setup of the options
-
androlyze.util.CLIUtil.
get_checks_from_cli
(args)[source]¶ Get the checks from run and prepare the dictionary for the “checks” argument of :py:method:`androlyze.action_query_result_db`
-
androlyze.util.CLIUtil.
get_filter_options_from_cli
(args)[source]¶ Get the filter options from run. Not all or even none may be specified
-
androlyze.util.CLIUtil.
get_result_db_filter_args_from_argparser
(args)[source]¶ Get filter args for result db from run and build kwargs for
ResultDatabaseStorage.get_results()
-
androlyze.util.CLIUtil.
print_query_result_db
(res, distict_generator=False, count=False, raw=False, interactive=True)[source]¶ Print the results from the result db (mongodb).
Parameters: count : bool, optional (default is False)
Only print count, not results
distict_generator : bool, optional (default is False)
Res is generator<object> created from the distinct(...) method of mongodb. If generaor<dict>, convert each dict to json. Otherwise just print.
raw : bool, optional (default is False)
Print raw data from gridfs Otherwise print json.
res : gridfs.grid_file.GridOutCursor or generator<object> or pymongo.cursor.Cursor
First if non_document and non_document_raw. Second if disctinct values wanted. Thirst otherwise. The results to print
interactive: bool, optional (default is True)
Iterate interactive through the result cursor
androlyze.util.Nil module¶
-
class
androlyze.util.Nil.
Nil
[source]¶ Bases:
object
Imitates the nil object from objective-c. Comparable to None, but ignores all method calls and attribute lookups.
Methods
-
androlyze.util.Nil.
nil
¶ Imitates the nil object from objective-c. Comparable to None, but ignores all method calls and attribute lookups.
androlyze.util.StopThread module¶
-
class
androlyze.util.StopThread.
StopThread
(*args, **kwargs)[source]¶ Bases:
threading.Thread
Extends the Thread with an Event and the terminate method like the multiprocessing api offers it.
Calling it will trigger the Event. Just implement your cleanup code for this event.
Attributes
Methods
androlyze.util.Util module¶
-
androlyze.util.Util.
calc_progress
(cur_cnt, total_cnt)[source]¶ Calculate progress and return it as float.
Parameters: cur_cnt : int
total_cnt : int
-
androlyze.util.Util.
clear_queue
(queue)[source]¶ Clear the queue by removing all elements (without blocking)
Parameters: queue : multiprocessing.Queue or Queue
-
androlyze.util.Util.
count_iterable_n_clone
(iterable)[source]¶ Parameters: iterable: iterable structure
-
androlyze.util.Util.
cs_classnames
(class_list, sort=True)[source]¶ Returns a comma separated str build from the name attribute
-
androlyze.util.Util.
datetime_to_iso8601
(dt)[source]¶ Convert a datetime object to a ISO-8601 string.
Examples
>>> from datetime import datetime ... datetime_to_iso8601(datetime.utcnow())
-
androlyze.util.Util.
format_exception
(exc_info_obj, as_string=True)[source]¶ Format the exception infos to a string
Parameters: exc_info_obj : (type, value, traceback)
An object like sys.exc_info() returns
as_string : bool
If true, return the formatted exception as string, not list<str>
Returns: str
-
androlyze.util.Util.
format_progress
(cur_cnt, total_cnt)[source]¶ Format progress and return it as str.
Parameters: cur_cnt : int
total_cnt : int
-
androlyze.util.Util.
get_fst_not_none
(sequence)[source]¶ Get the first object that is not None. Returns None if nothing found
-
androlyze.util.Util.
iso8601_to_datetime
(iso_dt)[source]¶ Convert a date represented as ISO-8601 string to a `datetime ` object (utc).
Examples
>>> from datetime import datetime ... iso8601_to_datetime(datetime.utcnow().isoformat())
-
androlyze.util.Util.
log_will_retry
(secs, exc=None, what='')[source]¶ Parameters: secs : int
Retry in secs seconds.
exc: Exception, optional (default is None)
Exception to log
what : str, optional (default is ‘’)
What to try again.
-
androlyze.util.Util.
module_names_from_class
(classes)[source]¶ Get module names from instantiated classes
-
androlyze.util.Util.
print_dyn_progress
(progress_str)[source]¶ Print progress on stdout.
Parameters: progress_str : str
-
androlyze.util.Util.
queue_to_list
(queue)[source]¶ Get all elements from the queue and return them as list.
Parameters: qeueue: multiprocessing.Queue
-
androlyze.util.Util.
set_androguard_path
(settings)[source]¶ Set the path to androguard from read from settings if not already in python path!
Parameters: settings : Settings
-
androlyze.util.Util.
sha256
(data)[source]¶ Calculate the sha256 hash
Parameters: data: object
Returns: str
sha256 as hexstring
-
androlyze.util.Util.
split_n_uniform_distri
(l, n=10)[source]¶ Split the list l into n sublists and try to fill each sublist with nearly the same number of elements. So achieve an uniform distribution in all sublists.
Examples
>>> split_n_uniform_distri(range(11)) [[0, 10], [1], [2], [3], [4], [5], [6], [7], [8], [9]]
-
androlyze.util.Util.
timeit
(func, *args, **kwargs)[source]¶ Returns the execution time in seconds of the func.
Returns: int
Execution time if no result value
tuple<int, object>
If the func has a return value, a tuple will be returned. 1. arg time, 2. arg result value
-
androlyze.util.Util.
transform_key
(key, from_mapping, to_mapping)[source]¶ Find the key in from_mapping and return the value of to_mapping at this index.
Parameters: key : str
from_mapping : list<str>
to_mapping : list<str>
Returns: appropriate value in the to_mapping
-
androlyze.util.Util.
utc2local
(utc_datetime)[source]¶ Convert datetime object in utc to local time zone.
Parameters: utc_datetime : datetime
Datetime object with utc timezone
Returns: datetime
Datetime object with local timezone
Examples
>>> from datetime import datetime ... print utc2local(datetime.utcnow())