parameters: ()
docstring: Main function
  
      parse arguments and call start
docstring_summary: Main function
docstring_tokens: Main function
function: def __main__():
      """
      Main function
  
      parse arguments and call start
      """
  
      arg_parser = argparse.ArgumentParser(
          description="HHK file creator")
      arg_parser.add_argument(
          dest="input_file",
          help="input file or directory")
      arg_parser.add_argument(
          dest="out_file",
          help="output file")
      arg_parser.add_argument(
          dest="merge_file",
          nargs="?",
          help="index file for merge")
      arg_parser.add_argument(
          "--baseuri",
          dest="base_uri",
          required=False,
          help="base URI for file links")
      arg_parser.add_argument(
          "--debug",
          dest="debug",
          action="store_true",
          required=False,
          help="Show debug messages in console")
  
      args = arg_parser.parse_args()
  
      init_logger(args.debug)
  
      input_file = args.input_file
      out_file = args.out_file
      merge_file = args.merge_file
      base_uri = args.base_uri
  
      try:
          if not os.path.exists(input_file):
              raise RuntimeError("Input file/directory '{}' not found"
                                 .format(input_file))
  
          index = {}  # dict(keyword: set((title, uri)))
          if os.path.isfile(input_file):
              process_file(input_file, index, base_uri)
          elif os.path.isdir(input_file):
              process_dir(input_file, index, base_uri)
          else:
              raise RuntimeError("Invalid file type: {}".format(input_file))
  
          if merge_file:
              load_index(merge_file, index)
  
          save_index(index, out_file)
      except Exception as ex:
          _LOGGER.error(ex)
          raise
          sys.exit(1)
function_tokens: def __main__ ( ) : arg_parser = argparse . ArgumentParser ( description = "HHK file creator" ) arg_parser . add_argument ( dest = "input_file" , help = "input file or directory" ) arg_parser . add_argument ( dest = "out_file" , help = "output file" ) arg_parser . add_argument ( dest = "merge_file" , nargs = "?" , help = "index file for merge" ) arg_parser . add_argument ( "--baseuri" , dest = "base_uri" , required = False , help = "base URI for file links" ) arg_parser . add_argument ( "--debug" , dest = "debug" , action = "store_true" , required = False , help = "Show debug messages in console" ) args = arg_parser . parse_args ( ) init_logger ( args . debug ) input_file = args . input_file out_file = args . out_file merge_file = args . merge_file base_uri = args . base_uri try : if not os . path . exists ( input_file ) : raise RuntimeError ( "Input file/directory '{}' not found" . format ( input_file ) ) index = { } # dict(keyword: set((title, uri))) if os . path . isfile ( input_file ) : process_file ( input_file , index , base_uri ) elif os . path . isdir ( input_file ) : process_dir ( input_file , index , base_uri ) else : raise RuntimeError ( "Invalid file type: {}" . format ( input_file ) ) if merge_file : load_index ( merge_file , index ) save_index ( index , out_file ) except Exception as ex : _LOGGER . error ( ex ) raise sys . exit ( 1 )