thutils package

Submodules

thutils.binary_writer module

@author: Tsuyoshi Hombashi

class thutils.binary_writer.BinaryWriter(io_size_byte=65536, byte_continuity=30)[source]
get_write_binary_data(size_byte)[source]
write_binary(file_path, write_size_byte, permission='-rw-r--r--')[source]

thutils.cache module

@author: Tsuyoshi Hombashi

class thutils.cache.CommandCache[source]
cache_lifetime_sec = 0
classmethod clear()[source]
classmethod execute(command, suffix='')[source]
classmethod initialize()[source]
class thutils.cache.memoize(function)[source]

thutils.common module

@author: Tsuyoshi Hombashi

class thutils.common.BaseObject[source]

Bases: object

debug(message='')
to_string()
class thutils.common.MinMaxObject[source]

Bases: thutils.common.BaseObject

average()
diff()
max_value
min_value
update(value)
exception thutils.common.NotInstallError[source]

Bases: exceptions.Exception

thutils.common.bytes_to_humanreadable(byte)[source]
thutils.common.command_to_filename(command, suffix='')[source]
thutils.common.compare_version(lhs_version, rhs_version)[source]

<Major>.<Minor>.<Revision> 形式のバージョン文字列を比較する。

Returns:0<: LHSがRHSより小さい 0: LHS == RHS 0>: LHSがRHSより大きい
Return type:int
thutils.common.convert_value(value)[source]
thutils.common.debug_dict(dict_input, symbol_table, convert_func=<function dump_dict>)[source]
thutils.common.diffItemList(item_list, remove_list)[source]
thutils.common.dump_dict(dict_input, indent=4)[source]

辞書型変数を文字列に変換して返す

thutils.common.get_execution_command()[source]
thutils.common.get_integer_digit(value)[source]
thutils.common.get_list_item(input_list, index)[source]
thutils.common.get_number_of_digit(value)[source]
thutils.common.get_text_len(text)[source]
thutils.common.get_var_name(var, symboltable)[source]
thutils.common.humanreadable_to_byte(readable_size, kilo_size=1024)[source]
Parameters:
  • str – readable_size. human readable size (bytes). e.g. 256 M
  • int – size of kilo. 1024 or 1000
Raises:

ValueError

thutils.common.humanreadable_to_kb(readable_size)[source]
thutils.common.is_empty_list_or_tuple(value)[source]
thutils.common.is_empty_string(value)[source]
thutils.common.is_float(value)[source]
thutils.common.is_hex(value)[source]
thutils.common.is_install_command(command)[source]
thutils.common.is_integer(value)[source]
thutils.common.is_list_or_tuple(value)[source]
thutils.common.is_nan(value)[source]
thutils.common.is_not_empty_list_or_tuple(value)[source]
thutils.common.is_not_empty_string(value)[source]
空白文字(, ,

)を除いた文字数が0より大きければTrueを返す

thutils.common.removeItemFromList(item_list, item)[source]
thutils.common.removeListFromList(input_list, remove_list)[source]
thutils.common.safe_division(dividend, divisor)[source]
Returns:nan: invalid arguments
Return type:float
thutils.common.sleep_wrapper(sleep_second, dry_run=False)[source]
thutils.common.split_line_list(line_list, re_line_separator=<_sre.SRE_Pattern object>, is_include_matched_line=False, is_strip=True)[source]
thutils.common.strtobool_wrapper(value)[source]
try:
import distutils.util return bool(distutils.util.strtobool(value))

except ImportError:

thutils.common.verify_install_command(command_list)[source]

thutils.data_property module

@author: Tsuyoshi Hombashi

class thutils.data_property.Align[source]
AUTO = <thutils.data_property.__AlignData instance>
CENTER = <thutils.data_property.__AlignData instance>
LEFT = <thutils.data_property.__AlignData instance>
RIGHT = <thutils.data_property.__AlignData instance>
class thutils.data_property.ColumnDataPeroperty[source]

Bases: thutils.common.BaseObject

align
decimal_places
padding_len
typecode
update_body(prop)
update_header(prop)
update_padding_len(padding_len)
class thutils.data_property.DataPeroperty(data)[source]

Bases: thutils.common.BaseObject

additional_format_len
align
data
decimal_places
integer_digits
str_len
type_format
typecode
class thutils.data_property.PropertyExtractor[source]
classmethod extract_column_property_list(header_list, data_matrix)[source]
classmethod extract_data_property_matrix(data_matrix)[source]
static get_additional_format_len(data)[source]
classmethod get_align_from_typecode(typecode)[source]
static get_base_float_len(integer_digits, decimal_places)[source]
class thutils.data_property.Typecode[source]
FLOAT = 2
INT = 1
NONE = 0
STRING = 4
classmethod get_typecode_from_bitmap(typecode_bitmap)[source]

thutils.environment module

@author: Tsuyoshi Hombashi

class thutils.environment.EnvironmentInfo[source]
EKN_DateTime = 'Date Time'
EKN_PlatformMachine = 'Platform Machine'
EKN_PlatformNode = 'Platform Node'
EKN_PlatformProcessor = 'Platform Processor'
EKN_PlatformRelease = 'Platform Release'
EKN_PlatformSystem = 'Platform System'
EKN_PlatformVersion = 'Platform Version'
EKN_ProgramVersion = 'Program Version'
EKN_PythonVersion = 'Python Version'
KN_DistributionName = 'Distribution Name'
KN_DistributionVersion = 'Distribution Version'
classmethod getGeneralInfoDict()[source]
classmethod getGeneralInfoMatrix()[source]

thutils.gfile module

@author: Tsuyoshi Hombashi

exception thutils.gfile.EmptyFileError[source]

Bases: exceptions.Exception

class thutils.gfile.FileManager[source]
classmethod chmod(path, permission_text)[source]
Parameters:permission_text (str) – “ls -l” style permission string. e.g. -rw-r–r–
classmethod copy_file(src_path, dst_path)[source]
classmethod initialize(dry_run)[source]
classmethod make_directory(dir_path, force=False)[source]
classmethod moveFile(src_path, dst_path)[source]
classmethod removeMatchDirectory(search_dir_path, re_target_list)[source]
classmethod removeMatchFileRecursively(search_dir_path, re_remove_list)[source]
classmethod remove_directory(path)[source]
classmethod remove_file(path)[source]
classmethod remove_object(path)[source]
classmethod rename(src_path, dst_path)[source]
classmethod touch(touch_path)[source]
exception thutils.gfile.FileNotFoundError[source]

Bases: exceptions.Exception

class thutils.gfile.FileType[source]
DIRECTORY = 2
FILE = 1
class thutils.gfile.FileTypeChecker[source]
class FileType
BINARY = 'data'
TEXT = 'ASCII text'
classmethod FileTypeChecker.get_file_type(file_path)
classmethod FileTypeChecker.is_text_file(file_path)
exception thutils.gfile.InvalidFilePathError[source]

Bases: exceptions.Exception

exception thutils.gfile.NullPathError[source]

Bases: exceptions.Exception

thutils.gfile.check_file_existence(path)[source]
Returns:

FileType

Return type:

int

Raises:
  • InvalidFilePathError
  • FileNotFoundError
  • RuntimeError
thutils.gfile.findDirectory(search_root_dir_path, re_pattern, find_count=-1)[source]
thutils.gfile.findFile(search_root_dir_path, re_pattern_text)[source]
thutils.gfile.findFileAll(search_root_dir_path, check_func, re_pattern_text, find_count=9223372036854775807)[source]
thutils.gfile.parseLsPermissionText(permission_text)[source]

parse “ls -l” style permission text: e.g. -rw-r–r–

thutils.gfile.parsePermission3Char(permission)[source]

‘rwx’ 形式のアクセス権限文字列 permission を8進数形式に変換する

Returns:
Return type:int
thutils.gfile.replace_symbol(file_name, replacement_text='')[source]
thutils.gfile.sanitize_file_name(path, replacement_text='')[source]
thutils.gfile.validate_path(input_path)[source]

thutils.gtime module

@author: Tsuyoshi Hombashi

class thutils.gtime.DateTimeRange(start_datetime, end_datetime, time_format='%Y-%m-%d %H:%M:%S')[source]

Bases: thutils.common.BaseObject

discard(discard_percent)

時間範囲の discard_percent / 2 [%] の時間分、開始・終了時刻をずらす。

end_datetime
equals(rhs)
getDeltaSecond()
getEndTimeText()
getOptionString()
getStartTimeText()
getTimeDelta()
Return value:
datetime.timedelta
isValidTimeRange()
isWithin(input_datetime)
squeezeTimeRange(datetime_range)

time inversionを発生させない範疇で時間範囲を狭める。

start_datetime
to_string(joint=' - ', time_format=None)
verifyTimeRange()
raise:
TypeError ValueError
widenTimeRange(datetime_range)

時間範囲を広げる。

class thutils.gtime.Format[source]
DATETIME_LIST = ['%Y-%m-%d %H:%M:%S', '%Y%m%dT%H%M%S', '%Y-%m-%dT%H:%M:%S', '%Y/%m/%d %H:%M:%S']
class ISO
DATE = '%Y-%m-%d'
DATETIME = '%Y-%m-%d %H:%M:%S'
TIME = '%H:%M:%S'
class Format.ISO8601
class Basic
DATE = '%Y%m%d'
DATETIME = '%Y%m%dT%H%M%S'
TIME = '%H%M%S'
class Format.ISO8601.Extended
DATE = '%Y-%m-%d'
DATETIME = '%Y-%m-%dT%H:%M:%S'
TIME = '%H:%M:%S'
Format.ISO_DATETIME_LIST = ['%Y-%m-%d %H:%M:%S', '%Y%m%dT%H%M%S', '%Y-%m-%dT%H:%M:%S']
Format.JST_DATE = '%Y/%m/%d'
class thutils.gtime.RegularExpression[source]
class ISO
DATE = '[1-2][\\d]{3}-[0-1][\\d]-[0-3][\\d]'
DATETIME = '[1-2][\\d]{3}-[0-1][\\d]-[0-3][\\d] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]'
DATETIME_WITH_TZ = '[1-2][\\d]{3}-[0-1][\\d]-[0-3][\\d] [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][\\d]{4}'
TIME = '[0-2][0-9]:[0-5][0-9]:[0-5][0-9]'
TIMEZONE = '[+-][\\d]{4}'
YEAR = '[1-2][\\d]{3}'
class thutils.gtime.TimeMeasure(message, log_level=20)[source]

Bases: object

logging = <module 'logging' from '/usr/lib/python2.7/logging/__init__.pyc'>
message
start()[source]
stop()[source]
thutils.gtime.convertHumanReadableToSecond(readable_time)[source]
thutils.gtime.findValidTimeFormat(datetime_string, time_format_list)[source]
thutils.gtime.getTimeDeltaSecond(start_datetime, end_datetime)[source]
thutils.gtime.getTimeUnitSecondsCoefficient(unit)[source]
thutils.gtime.is_datetime(value)[source]
thutils.gtime.is_valid_time_format(datetime_string, time_format)[source]
thutils.gtime.toDateTime(datetime_string, time_format, timezone='')[source]
thutils.gtime.toDateTimeEx(datetime_string, time_format_list)[source]

thutils.loader module

@author: Tsuyoshi Hombashi

required:https://pypi.python.org/pypi/voluptuous
class thutils.loader.JsonLoader[source]
classmethod load(json_file_path, schema=None)
Parameters:

json_file_path (str) – json_file_path: path of the json file to be read schema: voluptuous schema

Returns:

Dictionary storing the parse results of JSON

Return type:

dictionary

Raises:
  • ImportError
  • InvalidFilePathError
  • FileNotFoundError
  • RuntimeError
  • ValueError
classmethod loads(json_text, schema=None)
Parameters:
  • json_text (str) – json text to be parse
  • schema (voluptuous.Schema) – schema of voluptuous
Returns:

Dictionary storing the parse results of JSON

Return type:

dictionary

Raises:
  • ImportError
  • RuntimeError
  • ValueError

thutils.logger module

@author: Tsuyoshi Hombashi

class thutils.logger.LogLevelText[source]
ERROR = 'ERROR'
FATAL = 'FATAL'
INFO = 'INFO'
WARN = 'WARN'
class thutils.logger.logger[source]

classdocs

LOG_EXTENSION = '.log'
RE_LogExtension = '\\.log$'
classmethod clear_log()[source]
classmethod debug(msg, caller=None)[source]
classmethod debug_logging_count()[source]
classmethod error(msg, caller=None)[source]
classmethod exception(exception, msg='')[source]
classmethod fatal(msg, caller=None)[source]
classmethod get_log()[source]
classmethod info(message, caller=None)[source]
classmethod initialize(program_filename, dry_run, print_stack_trace, with_no_log, stdout_log_level, file_log_level=10, output_dir_path='.')[source]
classmethod warn(msg, caller=None)[source]
classmethod write(msg, log_level, caller=None)[source]

thutils.main module

@author: Tsuyoshi Hombashi

class thutils.main.Main(function)[source]
KEYBOARD_INTERRUPT_FORMAT = 'Keyboard Interrupt from %s'

thutils.option module

@author: Tsuyoshi Hombashi

class thutils.option.ArgumentParserObject[source]

Bases: object

wrapper class of argparse

class GroupName[source]
MISC = 'Miscellaneous'
PROFILE = 'Profile'
SQL = 'SQL'
TIME_RANGE = 'Time Range'
ArgumentParserObject.addMakeArgumentGroup()[source]
ArgumentParserObject.add_argument_group(group_name)[source]
ArgumentParserObject.add_dry_run_option()[source]
ArgumentParserObject.add_profile_argument_group()[source]
ArgumentParserObject.add_run_option()[source]
ArgumentParserObject.add_sql_argument_group()[source]
ArgumentParserObject.add_time_argument_group()[source]
ArgumentParserObject.add_time_range_argument_group(valid_time_format_list, start_time_help_msg='', end_time_help_msg='')[source]
ArgumentParserObject.make(version, description='', epilog='')[source]
ArgumentParserObject.parse_args()[source]
static ArgumentParserObject.validate_time_range_option(options, valid_time_format_list, is_check_time_inversion=True)[source]
class thutils.option.MakeOption[source]
CLEAN = 'clean'
MAKE = 'make'
OVERWRITE = 'overwrite'
SKIP = 'skip'
thutils.option.getGeneralOptionList(options)[source]

thutils.sqlite module

@author: Tsuyoshi Hombashi

exception thutils.sqlite.AttributeNotFoundError[source]

Bases: exceptions.Exception

exception thutils.sqlite.DatabaseError[source]

Bases: exceptions.Exception

exception thutils.sqlite.MissmatchError[source]

Bases: exceptions.Exception

exception thutils.sqlite.NullDatabaseConnectionError[source]

Bases: exceptions.Exception

class thutils.sqlite.SqlQuery[source]
classmethod make_datetimerange_where_list(datetime_range, start_attr_name, end_attr_name)[source]
classmethod make_insert(table_name, insert_tuple, is_insert_many=False)[source]
classmethod make_select(select, table, where=None, extra=None)[source]

SQLite query作成補助関数

Returns:SQLite query string
Return type:str
classmethod make_where(key, value, operation='=')[source]
classmethod make_where_in(key, value_list)[source]
classmethod make_where_not_in(key, value_list)[source]
classmethod sanitize(query_item)[source]
classmethod to_attr_str(name, operation_query='')[source]
classmethod to_attr_str_list(name_list, operation_query=None)[source]
classmethod to_table_str(name)[source]
classmethod to_value_str(value)[source]
classmethod to_value_str_list(value_list)[source]
class thutils.sqlite.SqliteWrapper(dry_run=False, profile=False)[source]

Bases: object

wrapper class of sqlite3

AN_DB_CREATE_TIME = 'database_create_time'
AN_DB_NAME = 'database_name'
AN_DB_VERSION = 'database_version'
MISC_TABLE_LIST = ['table_configuration', 'database_information', 'sql_profile']
TN_DB_INFO = 'database_information'
TN_SQL_PROFILE = 'sql_profile'
TN_TABLE_CONFIG = 'table_configuration'
checkAccessPermission(valid_permission_list)[source]
check_connection()[source]
Raises:NullDatabaseConnectionError – if not connected to a SQLite database file
check_database_name(expected_name)[source]
Raises:
  • TableNotFoundError – table not found in the database
  • AttributeError – attribute not found in the database
  • MissmatchError – database name missmatch found
check_database_version(compare_version)[source]
Raises:
  • TableNotFoundError – table not found in the database
  • AttributeError – attribute not found in the database
  • MissmatchError – database version miss match found
close()[source]
commit()[source]
connect(database_path, mode='w')[source]
Parameters:

mode (str) – “r”: read only “w”: DBファイルを新規作成する。既存ファイルは削除する。 “a”: 既存DBファイルに追記する。

Raises:
  • TypeError
    • database_path が文字列でない
    • mode が文字列でない
  • FileNotFoundError – database_path not found
  • InvalidFilePathError – database_path is invalid
  • ValueError
    • database_path がディレクトリ
    • mode が未サポートの値
  • DatabaseError – file is not a valid SQLite binary file
connection
createIndex(table_name, attribute_name)[source]
createIndexList(table_name, attribute_name_list)[source]
create_db_info_table(db_name, db_version)[source]
create_table(table_name, attribute_description_list)[source]
create_table_with_data(table_name, attribute_name_list, data_matrix, index_attribute_list=())[source]
database_path
drop_table(table_name, is_drop_existing_table=True)[source]
dry_run
execute_insert(table_name, insert_record)[source]
execute_insert_many(table_name, insert_record_list)[source]
execute_select(select, table, where=None, extra=None)[source]
getValue(select, table, where=None, extra=None)[source]
getValueList(select, table, where=None, extra=None)[source]
get_attribute_name_list(table_name)[source]
get_attribute_type_list(table_name)[source]
get_database_name()[source]
get_database_version()[source]
get_profile(get_profile_count=50)[source]
get_table_name_list()[source]
get_total_changes()[source]
has_attribute(table_name, attribute_name)[source]
has_attribute_list(table_name, attribute_name_list)[source]
has_table(table_name)[source]
is_connected()[source]
mode
rollback()[source]
verify_attribute_existence(table_name, attribute_name)[source]
Raises:
  • sTypeError
  • TableNotFoundError
  • AttributeNotFoundError
verify_table_existence(table_name)[source]
Raises:
  • TypeError
  • TableNotFoundError
exception thutils.sqlite.TableNotFoundError[source]

Bases: exceptions.Exception

thutils.sqlite.append_table(con_src, con_dst, table_name)[source]
thutils.sqlite.connect_sqlite_database(db_path, mode, options=None)[source]

SQLiteデータベースファイルへのコネクションを返す。

thutils.sqlite.connect_sqlite_db_mem()[source]
thutils.sqlite.copy_table(con_src, con_dst, table_name)[source]
thutils.sqlite.getListFromQueryResult(result)[source]
Argument:Return value from a SQLite query response
Return type:list

thutils.subprocwrapper module

@author: Tsuyoshi Hombashi

class thutils.subprocwrapper.SubprocessWrapper(dry_run=False)[source]

Bases: object

dry_run
popen_command(command, std_in=None, environ=None)
run(command, ignore_error_list=())

thutils.syswrapper module

Module contents

exception thutils.NotInstallError[source]

Bases: exceptions.Exception

exception thutils.PermissionError[source]

Bases: exceptions.Exception

thutils.initialize_library(program_filename, options, output_dir_path='.')[source]