Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import hashlib, os, string
- from logging import info, warning, error, debug
- from component import ARGMPANEL
- from keyautomaton import VALIDATORWHIRL, VALIDATORMD5
- def assetValidator(component_index, dirname_files):
- session_argm = dirname_files + 'argm.session'
- component_dir = dirname_files + 'component/'
- size_session_argm = os.stat(session_argm).st_size
- if size_session_argm > 0:
- argm_session = open(session_argm,'w')
- argm_session.write('')
- argm_session.close()
- if os.path.isdir(component_dir):
- for V_lo1_C_component_index in component_index:
- # secara arrray atau tuples, file ini digunakan untuk memastikan, bahwa kontent file yang ada
- # didalam variable data_component_file adalah benar data yang digunakan sebagai asset data pada game.
- path_component_file = component_dir
- path_component_file+= V_lo1_C_component_index + '.argm'
- if os.path.exists(path_component_file):
- # dalam section ini code akan dibaca, kemudian akan dipass kedalam split data.
- # split data yang harus dibuat adalah _split_over_this_code_. tapi file harus
- # berhati-hati karena 1 newline akan mengubah hash dalam kode.
- data_component_file = open(path_component_file,'r')
- C_data_component_file = data_component_file.read()
- data_component_file.close()
- split_C_data_component_file = string.split(C_data_component_file,'_split_over_this_code_')
- for I_lo2_split_C_data_component_file, V_lo2_split_C_data_component_file in enumerate(split_C_data_component_file):
- if V_lo2_split_C_data_component_file != '':
- # bentuk alternatif switch, terdapat 3 kategori yang masuk kedalam Assets
- # Resources Game Management (ARGM), yaitu image/png, image/tga dan image/jpg
- # masing-masing memiliki extension data yang berbeda.
- if V_lo2_split_C_data_component_file[:4] == '.png':
- strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.png_separator_data_')
- elif V_lo2_split_C_data_component_file[:4] == '.tga':
- strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.tga_separator_data_')
- elif V_lo2_split_C_data_component_file[:4] == '.jpg':
- strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.jpg_separator_data_')
- # sesuai dengan technical Issue yang terdapa dalam windows, dimana algoritma
- # whirlpool tidak dapat dijalankan oleh python. maka akan dibuat algoritma
- # hash alternatif yaitu MD5.
- try:
- hash_data = hashlib.new('whirlpool', strip_V_lo2_split_C_data_component_file)
- compared_use = 'whirlpool'
- except ValueError, e:
- hash_data = hashlib.new('md5', strip_V_lo2_split_C_data_component_file)
- compared_use = 'md5'
- C_hash_data = hash_data.hexdigest()
- # validasi data, sesuai dengan index file yang dibutuhkan.
- if compared_use == 'whirlpool':
- class_compare_use = VALIDATORWHIRL()
- elif compared_use == 'md5':
- class_compare_use = VALIDATORMD5()
- if C_hash_data == class_compare_use.asset_key[V_lo1_C_component_index][I_lo2_split_C_data_component_file]:
- is_valid = 1
- else:
- is_valid = 0
- error('[Common ] Error Data on %s' % c_file_real)
- if is_valid == 1:
- ARGMPANEL(V_lo1_C_component_index, dirname_files).argmToTempFile(path_component_file.encode('utf-8'))
- else:
- print 'asset is NULL'
- else:
- print 'no_component'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement