示例#1
0
def main(argv):
  global _usedmodifiedtime, _verbosity, _debug
  try:
    opts, args = getopt.getopt(argv, "hv:md", ["help", "verbosity", "modified_time", "debug"])
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  
  for opt, val in opts:
    if opt in ("-h", "--help"):
      usage()
      sys.exit()
    elif opt in ("-d", "--debug"):
      _debug = True
    elif opt in ("-v", "--verbosity"):
      _verbosity = int(val)
    elif opt in ("-m", "--modified_time"):
      _usemodifiedtime = True

  if not _debug:
    # TODO(djlee): this is way too destructive!  could be several minutes where
    # site would report nothing found.
    # instead, do bookkeeping in python and set things to 'not found' at the end
    Directory.set_all_not_found()
    File.set_all_not_found()

  for (type, conf) in DIR_CONF.items():
    print "\n\n#########\nUpdating " + type + "\n#########\n"
    # stick in a compiled regex to the struct for use in process_files
    conf.regex = re.compile(r'.*\.(%s)$' % '|'.join(conf.file_extensions), re.I)
    for directory in conf.local_fileroot:
      # make sure there's a trailing slash
      if directory[-1] not in ('/', '\\'):
        directory += '/'
      for curdir, subdirs, files in os.walk(directory, topdown=True):
        process_files(conf, directory, curdir, files)
示例#2
0
def main(argv):
  global _usedmodifiedtime, _verbosity, _debug
  try:
    opts, args = getopt.getopt(argv, "hv:md", ["help", "verbosity", "modified_time", "debug"])
  except getopt.GetoptError:
    usage()
    sys.exit(2)
  
  for opt, val in opts:
    if opt in ("-h", "--help"):
      usage()
      sys.exit()
    elif opt in ("-d", "--debug"):
      _debug = True
    elif opt in ("-v", "--verbosity"):
      _verbosity = int(val)
    elif opt in ("-m", "--modified_time"):
      _usemodifiedtime = True


  for (type, conf) in DIR_CONF.items():
    orig_directories = Directory.objects.filter(found=True, type=type)
    orig_files = File.objects.filter(found=True, type=type)
    found_files = []
    print "\n\n#########\nUpdating " + type + "\n#########\n"
    # stick in a compiled regex to the struct for use in process_files
    conf.regex = re.compile(r'.*\.(%s)$' % '|'.join(conf.file_extensions), re.I)
    for directory in conf.local_fileroot:
      # make sure there's a trailing slash
      if directory[-1] not in ('/', '\\'):
        directory += '/'
      # Note: passing in a unicode string to os.walk makes every result get
      # returned in unicode
      for curdir, subdirs, files in os.walk(unicode(directory), topdown=True):
        found_files.extend(process_files(conf, directory, curdir, files))

    found_dir_paths = set(f.directory.absolute_path() for f in found_files)
    found_file_paths = set(f.absolute_path() for f in found_files)
    if _verbosity >= 2:
      print "Found %d files and %d directories" % (len(found_file_paths),
                                                   len(found_dir_paths))
    for dir in orig_directories:
      if dir.absolute_path() not in found_dir_paths:
        dir.found = False
        try: 
          if not _debug:
            dir.save()
        except OperationalError, e:
          print "Directory save caused exception: " + str(dir)
          print e
          print "Skipping..."
    for file in orig_files:
      if file.absolute_path() not in found_file_paths:
        file.found = False
        try: 
          if not _debug:
            file.save()
        except OperationalError, e:
          print "File save caused exception: " + str(file)
          print e
          print "Skipping..."