nodes: 0, module; 1, function_definition; 2, function_name:reconstruct_files; 3, parameters; 4, block; 5, identifier:input_dir; 6, expression_statement; 7, expression_statement; 8, with_statement; 9, string; 10, assignment; 11, with_clause; 12, comment:# Some datasets start with a ".", which confuses many programs; 13, block; 14, string_content:sorts ``input_dir`` and tries to reconstruct the subdirectories found; 15, identifier:input_dir; 16, call; 17, with_item; 18, for_statement; 19, expression_statement; 20, expression_statement; 21, if_statement; 22, attribute; 23, argument_list; 24, call; 25, pattern_list; 26, call; 27, block; 28, call; 29, assignment; 30, call; 31, block; 32, else_clause; 33, identifier:input_dir; 34, identifier:rstrip; 35, string; 36, attribute; 37, argument_list; 38, identifier:r; 39, identifier:ds; 40, identifier:fs; 41, attribute; 42, argument_list; 43, for_statement; 44, attribute; 45, argument_list; 46, identifier:output_dir; 47, binary_operator:'%s-sorted' % input_dir; 48, attribute; 49, argument_list; 50, with_statement; 51, block; 52, string_content:/; 53, identifier:nl; 54, identifier:notify; 55, string; 56, identifier:os; 57, identifier:walk; 58, identifier:input_dir; 59, identifier:f; 60, identifier:fs; 61, block; 62, attribute; 63, identifier:organize_dir; 64, identifier:input_dir; 65, string; 66, identifier:input_dir; 67, attribute; 68, identifier:exists; 69, identifier:output_dir; 70, with_clause; 71, block; 72, expression_statement; 73, string_content:Attempting to organize/reconstruct directory; 74, if_statement; 75, identifier:nl; 76, identifier:dicom; 77, string_content:%s-sorted; 78, identifier:os; 79, identifier:path; 80, with_item; 81, for_statement; 82, call; 83, comparison_operator:f[0]=='.'; 84, block; 85, call; 86, identifier:dset_dir; 87, call; 88, block; 89, attribute; 90, argument_list; 91, subscript; 92, string; 93, expression_statement; 94, attribute; 95, argument_list; 96, attribute; 97, argument_list; 98, with_statement; 99, identifier:nl; 100, identifier:notify; 101, binary_operator:'Warning: failed to auto-organize directory %s' % input_dir; 102, keyword_argument; 103, identifier:f; 104, integer:0; 105, string_content:.; 106, call; 107, identifier:nl; 108, identifier:run_in; 109, identifier:output_dir; 110, identifier:os; 111, identifier:listdir; 112, string; 113, with_clause; 114, block; 115, string; 116, identifier:input_dir; 117, identifier:level; 118, attribute; 119, attribute; 120, argument_list; 121, string_content:.; 122, with_item; 123, expression_statement; 124, string_content:Warning: failed to auto-organize directory %s; 125, attribute; 126, identifier:warning; 127, identifier:shutil; 128, identifier:move; 129, call; 130, call; 131, call; 132, call; 133, identifier:nl; 134, identifier:level; 135, attribute; 136, argument_list; 137, attribute; 138, argument_list; 139, attribute; 140, argument_list; 141, attribute; 142, argument_list; 143, attribute; 144, identifier:join; 145, identifier:r; 146, identifier:f; 147, attribute; 148, identifier:join; 149, identifier:r; 150, binary_operator:'i'+f; 151, identifier:nl; 152, identifier:notify; 153, binary_operator:'creating dataset from %s' % dset_dir; 154, attribute; 155, identifier:create_dset; 156, identifier:dset_dir; 157, identifier:os; 158, identifier:path; 159, identifier:os; 160, identifier:path; 161, string; 162, identifier:f; 163, string; 164, identifier:dset_dir; 165, identifier:nl; 166, identifier:dicom; 167, string_content:i; 168, string_content:creating dataset from %s
code: def reconstruct_files(input_dir):
      '''sorts ``input_dir`` and tries to reconstruct the subdirectories found'''
      input_dir = input_dir.rstrip('/')
      with nl.notify('Attempting to organize/reconstruct directory'):
          # Some datasets start with a ".", which confuses many programs
          for r,ds,fs in os.walk(input_dir):
              for f in fs:
                  if f[0]=='.':
                      shutil.move(os.path.join(r,f),os.path.join(r,'i'+f))
          nl.dicom.organize_dir(input_dir)
          output_dir = '%s-sorted' % input_dir
          if os.path.exists(output_dir):
              with nl.run_in(output_dir):
                  for dset_dir in os.listdir('.'):
                      with nl.notify('creating dataset from %s' % dset_dir):
                          nl.dicom.create_dset(dset_dir)
          else:
              nl.notify('Warning: failed to auto-organize directory %s' % input_dir,level=nl.level.warning)