Advertisement
moonshader

core.py

Nov 27th, 2014
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import hashlib, os, string
  4. from logging import info, warning, error, debug
  5.  
  6. from component import ARGMPANEL
  7. from keyautomaton import VALIDATORWHIRL, VALIDATORMD5
  8.  
  9. def assetValidator(component_index, dirname_files):
  10.    
  11.     session_argm = dirname_files + 'argm.session'
  12.     component_dir = dirname_files + 'component/'
  13.    
  14.     size_session_argm = os.stat(session_argm).st_size
  15.    
  16.     if size_session_argm > 0:
  17.         argm_session = open(session_argm,'w')
  18.         argm_session.write('')
  19.         argm_session.close()
  20.        
  21.     if os.path.isdir(component_dir):
  22.        
  23.         for V_lo1_C_component_index in component_index:
  24.            
  25.             # secara arrray atau tuples, file ini digunakan untuk memastikan, bahwa kontent file yang ada
  26.             # didalam variable data_component_file adalah benar data yang digunakan sebagai asset data pada game.
  27.             path_component_file = component_dir
  28.             path_component_file+= V_lo1_C_component_index + '.argm'
  29.            
  30.             if os.path.exists(path_component_file):
  31.                
  32.                 # dalam section ini code akan dibaca, kemudian akan dipass kedalam split data.
  33.                 # split data yang harus dibuat adalah _split_over_this_code_. tapi file harus
  34.                 # berhati-hati karena 1 newline akan mengubah hash dalam kode.
  35.                 data_component_file = open(path_component_file,'r')
  36.                 C_data_component_file = data_component_file.read()
  37.                 data_component_file.close()
  38.                
  39.                 split_C_data_component_file = string.split(C_data_component_file,'_split_over_this_code_')
  40.                
  41.                 for I_lo2_split_C_data_component_file, V_lo2_split_C_data_component_file in enumerate(split_C_data_component_file):
  42.                    
  43.                     if V_lo2_split_C_data_component_file != '':
  44.                        
  45.                         # bentuk alternatif switch, terdapat 3 kategori yang masuk kedalam Assets
  46.                         # Resources Game Management (ARGM), yaitu image/png, image/tga dan image/jpg
  47.                         # masing-masing memiliki extension data yang berbeda.
  48.                         if V_lo2_split_C_data_component_file[:4] == '.png':
  49.                             strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.png_separator_data_')
  50.                         elif V_lo2_split_C_data_component_file[:4] == '.tga':
  51.                             strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.tga_separator_data_')
  52.                         elif V_lo2_split_C_data_component_file[:4] == '.jpg':
  53.                             strip_V_lo2_split_C_data_component_file = string.strip(V_lo2_split_C_data_component_file, '.jpg_separator_data_')
  54.                            
  55.                         # sesuai dengan technical Issue yang terdapa dalam windows, dimana algoritma
  56.                         # whirlpool tidak dapat dijalankan oleh python. maka akan dibuat algoritma
  57.                         # hash alternatif yaitu MD5.
  58.                         try:
  59.                             hash_data = hashlib.new('whirlpool', strip_V_lo2_split_C_data_component_file)
  60.                             compared_use = 'whirlpool'
  61.                            
  62.                         except ValueError, e:
  63.                             hash_data = hashlib.new('md5', strip_V_lo2_split_C_data_component_file)
  64.                             compared_use = 'md5'
  65.                            
  66.                         C_hash_data = hash_data.hexdigest()
  67.                        
  68.                         # validasi data, sesuai dengan index file yang dibutuhkan.
  69.                         if compared_use == 'whirlpool':
  70.                             class_compare_use = VALIDATORWHIRL()
  71.                         elif compared_use == 'md5':
  72.                             class_compare_use = VALIDATORMD5()
  73.                            
  74.                            
  75.                         if C_hash_data == class_compare_use.asset_key[V_lo1_C_component_index][I_lo2_split_C_data_component_file]:
  76.                             is_valid = 1
  77.                            
  78.                         else:
  79.                             is_valid = 0
  80.                             error('[Common      ] Error Data on %s' % c_file_real)
  81.                 if is_valid == 1:
  82.                     ARGMPANEL(V_lo1_C_component_index, dirname_files).argmToTempFile(path_component_file.encode('utf-8'))
  83.            
  84.             else:
  85.                 print 'asset is NULL'
  86.     else:
  87.        
  88.         print 'no_component'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement