import os
import json
from argparse import ArgumentParser

if __name__ == "__main__":
  # Get config
  parser = ArgumentParser()
  parser.add_argument("-o", "--output_dir", dest="output_dir", required=True)
  options = parser.parse_args()

  # Initialization
  conf = dict()
  conf_name = os.environ['conf_name']
  search_prefix = "SEARCHLOPQ_"
  storer_prefix = "ST_"
  hbase_prefix = "HBI_"

  # Generic ingestion settings
  verbose = os.getenv('verbose', 0)
  conf[search_prefix + "verbose"] = verbose
  conf[search_prefix + 'get_pretrained_model'] = False

  conf[search_prefix + 'storer_prefix'] = storer_prefix
  conf[search_prefix + 'indexer_prefix'] = hbase_prefix
  conf[search_prefix + 'indexer_type'] = "hbase_indexer_minimal"
  storer_type = os.environ['storer']
  if storer_type == "local":
    conf[search_prefix + 'storer_type'] = storer_type
    conf[storer_prefix + 'base_path'] = os.getenv('storer_base_path', './data/index')
    conf[storer_prefix + 'verbose'] = verbose
  # TODO: deal with AWS

  # Extraction settings
  extr_type = os.environ['extr_type']
  if extr_type == "dlibface":
    # Extractions options
    featurizer_prefix = "DLIB_"
    conf[search_prefix + 'featurizer_prefix'] = featurizer_prefix
    conf[search_prefix + 'featurizer_type'] = "dlib"
    conf[search_prefix + 'detector_type'] = "dlib"
    conf[search_prefix + 'input_type'] = "face"
    conf[featurizer_prefix + 'pred_path'] = "./data/models/shape_predictor_68_face_landmarks.dat"
    conf[featurizer_prefix + 'rec_path'] = "./data/models/dlib_face_recognition_resnet_model_v1.dat"
  elif extr_type == "sbpycaffeimg":
    featurizer_prefix = "SBPY_"
    conf[search_prefix + 'featurizer_prefix'] = featurizer_prefix
    conf[search_prefix + 'featurizer_type'] = "sbpycaffe"
    conf[search_prefix + 'detector_type'] = "full"
    conf[search_prefix + 'input_type'] = "image"
    conf[featurizer_prefix + 'sbcaffe_path'] = "./data/models/caffe_sentibank_train_iter_250000",
    conf[featurizer_prefix + 'imgmean_path'] = "./data/models/imagenet_mean.npy"
  else:
    raise ValueError("Unknown extraction type: {}".format(extr_type))

  # HBase settings
  conf[hbase_prefix + 'host'] =  os.environ['hbase_host']
  conf[hbase_prefix + 'table_sha1infos'] = os.environ['table_sha1infos']
  conf[hbase_prefix + 'table_updateinfos'] = os.environ['table_updateinfos']
  conf[hbase_prefix + 'batch_update_size'] = os.environ['batch_update_size']
  conf[hbase_prefix + 'pool_thread'] = 1

  # Local input settings
  if os.environ['input_type'] == "local":
    conf[search_prefix + 'file_input'] = True

  # Search parameters
  conf[search_prefix + 'model_type'] = os.environ['model_type']
  conf[search_prefix + 'nb_train'] = os.environ['nb_train']
  conf[search_prefix + 'lopq_V'] = os.environ['lopq_V']
  conf[search_prefix + 'lopq_M'] = os.environ['lopq_M']
  conf[search_prefix + 'lopq_subq'] = os.environ['lopq_subq']
  if conf[search_prefix + 'model_type'] == "lopq_pca":
    conf[search_prefix + 'nb_train_pca'] = os.environ['nb_train_pca']
    conf[search_prefix + 'lopq_pcadims'] = os.environ['lopq_pcadims']

  if not os.path.exists(options.output_dir):
    os.mkdir(options.output_dir)

  json.dump(conf, open(os.path.join(options.output_dir,'conf_search_'+conf_name+'.json'),'wt'), sort_keys=True, indent=4)


@@ -430,16 +430,20 @@
 rbose = 
+int(
 os.geten
@@ -457,16 +457,17 @@
 ose', 0)
+)
 %0A  conf%5B
@@ -2398,24 +2398,28 @@
 te_size'%5D = 
+int(
 os.environ%5B'
@@ -2437,16 +2437,17 @@
 e_size'%5D
+)
 %0A  conf%5B
@@ -2714,24 +2714,28 @@
 b_train'%5D = 
+int(
 os.environ%5B'
@@ -2744,16 +2744,17 @@
 _train'%5D
+)
 %0A  conf%5B
@@ -2777,24 +2777,28 @@
 'lopq_V'%5D = 
+int(
 os.environ%5B'
@@ -2805,16 +2805,17 @@
 lopq_V'%5D
+)
 %0A  conf%5B
@@ -2838,24 +2838,28 @@
 'lopq_M'%5D = 
+int(
 os.environ%5B'
@@ -2866,16 +2866,17 @@
 lopq_M'%5D
+)
 %0A  conf%5B
@@ -2902,24 +2902,28 @@
 pq_subq'%5D = 
+int(
 os.environ%5B'
@@ -2933,16 +2933,17 @@
 q_subq'%5D
+)
 %0A  if co
@@ -3029,24 +3029,28 @@
 ain_pca'%5D = 
+int(
 os.environ%5B'
@@ -3063,16 +3063,17 @@
 in_pca'%5D
+)
 %0A    con
@@ -3104,24 +3104,28 @@
 pcadims'%5D = 
+int(
 os.environ%5B'
@@ -3138,16 +3138,17 @@
 cadims'%5D
+)
 %0A%0A  if n

fix settings integer