def add_items(fs_items_set, db_items, create_or_resurrect_db_item, parent):
 items = []
 new_items = []
 db_items_set = set(db_items)
 items_to_delete = (db_items_set - fs_items_set)
 items_to_create = (fs_items_set - db_items_set)
 for name in items_to_delete:
  db_items[name].makeobsolete()
 for name in (db_items_set - items_to_delete):
  items.append(db_items[name])
 for name in items_to_create:
  item = create_or_resurrect_db_item(name)
  items.append(item)
  new_items.append(item)
  try:
   item.save()
  except Exception:
   logging.exception('Error while adding %s', item)
 return (items, new_items)

def add_items ( fs_items_set , db_items , create_or_resurrect_db_item , parent ) : items = [ ] new_items = [ ] db_items_set = set ( db_items ) items_to_delete = ( db_items_set - fs_items_set ) items_to_create = ( fs_items_set - db_items_set ) for name in items_to_delete : db_items [ name ] . makeobsolete ( ) for name in ( db_items_set - items_to_delete ) : items . append ( db_items [ name ] ) for name in items_to_create : item = create_or_resurrect_db_item ( name ) items . append ( item ) new_items . append ( item ) try : item . save ( ) except Exception : logging . exception ( 'Error while adding %s' , item ) return ( items , new_items )
add/make obsolete the database items to correspond to the filesystem .