parameters: (filepath)
return_statement: return epim_dir
docstring: From EPIM HTML File to Folder of HTML Files
docstring_summary: From EPIM HTML File to Folder of HTML Files
docstring_tokens: From EPIM HTML File to Folder of HTML Files
function: def epim_html_file_to_hier_files(filepath):
      """From EPIM HTML File to Folder of HTML Files"""
      epim_dir = os.path.join(cons.TMP_FOLDER, "EPIM")
      if os.path.isdir(epim_dir): shutil.rmtree(epim_dir)
      curr_state = 0
      nodes_levels = []
      nodes_names = []
      nodes_content = []
      curr_node_idx = 0
      html_prefix = ""
      with open(filepath, 'r') as fd:
          for html_row in fd:
              if curr_state == 0:
                  html_prefix += html_row
                  if "<body>" in html_row: curr_state = 1
              elif curr_state == 1:
                  if not "href" in html_row:
                      curr_state = 2
                      continue
                  nodes_levels.append(html_row.count("&nbsp; &nbsp;"))
              elif curr_state == 2:
                  if html_row.startswith("<span class=rvts1>"):
                      nodes_names.append(support.clean_from_chars_not_for_filename(html_row[18:-14]))
                      nodes_content.append("")
                      curr_state = 3
              elif curr_state == 3:
                  if html_row.startswith("<ul class=list0>"):
                      curr_node_idx += 1
                      curr_state = 2
                  elif html_row.startswith("</body></html>"):
                      curr_node_idx += 1
                      curr_state = 4
                  else: nodes_content[curr_node_idx] += html_row
              else: break
      print len(nodes_levels), nodes_levels
      print len(nodes_names), nodes_names
      filedir, filename = os.path.split(filepath)
      dest_folder = [epim_dir]
      for i,node_name in enumerate(nodes_names):
          if i>0:
              if nodes_levels[i] > nodes_levels[i-1]:
                  dest_folder.append(os.path.join(dest_folder[-1], nodes_names[i-1]))
                  print dest_folder[-1]
              elif nodes_levels[i] < nodes_levels[i-1]:
                  for back_jumps in range(nodes_levels[i-1] - nodes_levels[i]):
                      dest_folder.pop()
          if not os.path.isdir(dest_folder[-1]):
              os.makedirs(dest_folder[-1])
              for filepath_to_cpy in glob.glob(os.path.join(filedir, "*")):
                  if filepath_to_cpy == filepath: continue
                  shutil.copy(filepath_to_cpy, dest_folder[-1])
          dest_filepath = os.path.join(dest_folder[-1], support.clean_from_chars_not_for_filename(node_name)+".htm")
          with open(dest_filepath, 'w') as fd:
              fd.write(html_prefix+nodes_content[i]+"</body></html>")
      return epim_dir
function_tokens: def epim_html_file_to_hier_files ( filepath ) : epim_dir = os . path . join ( cons . TMP_FOLDER , "EPIM" ) if os . path . isdir ( epim_dir ) : shutil . rmtree ( epim_dir ) curr_state = 0 nodes_levels = [ ] nodes_names = [ ] nodes_content = [ ] curr_node_idx = 0 html_prefix = "" with open ( filepath , 'r' ) as fd : for html_row in fd : if curr_state == 0 : html_prefix += html_row if "<body>" in html_row : curr_state = 1 elif curr_state == 1 : if not "href" in html_row : curr_state = 2 continue nodes_levels . append ( html_row . count ( "&nbsp; &nbsp;" ) ) elif curr_state == 2 : if html_row . startswith ( "<span class=rvts1>" ) : nodes_names . append ( support . clean_from_chars_not_for_filename ( html_row [ 18 : - 14 ] ) ) nodes_content . append ( "" ) curr_state = 3 elif curr_state == 3 : if html_row . startswith ( "<ul class=list0>" ) : curr_node_idx += 1 curr_state = 2 elif html_row . startswith ( "</body></html>" ) : curr_node_idx += 1 curr_state = 4 else : nodes_content [ curr_node_idx ] += html_row else : break print len ( nodes_levels ) , nodes_levels print len ( nodes_names ) , nodes_names filedir , filename = os . path . split ( filepath ) dest_folder = [ epim_dir ] for i , node_name in enumerate ( nodes_names ) : if i > 0 : if nodes_levels [ i ] > nodes_levels [ i - 1 ] : dest_folder . append ( os . path . join ( dest_folder [ - 1 ] , nodes_names [ i - 1 ] ) ) print dest_folder [ - 1 ] elif nodes_levels [ i ] < nodes_levels [ i - 1 ] : for back_jumps in range ( nodes_levels [ i - 1 ] - nodes_levels [ i ] ) : dest_folder . pop ( ) if not os . path . isdir ( dest_folder [ - 1 ] ) : os . makedirs ( dest_folder [ - 1 ] ) for filepath_to_cpy in glob . glob ( os . path . join ( filedir , "*" ) ) : if filepath_to_cpy == filepath : continue shutil . copy ( filepath_to_cpy , dest_folder [ - 1 ] ) dest_filepath = os . path . join ( dest_folder [ - 1 ] , support . clean_from_chars_not_for_filename ( node_name ) + ".htm" ) with open ( dest_filepath , 'w' ) as fd : fd . write ( html_prefix + nodes_content [ i ] + "</body></html>" ) return epim_dir