def tag_source(source_name, tag_names=None):
 if ((not tag_names) or (tag_names is None)):
  return
 session = Session()
 try:
  source = session.query(ArchiveSource).filter((ArchiveSource.name == source_name)).first()
  if (not source):
   log.critical((u'Source `%s` does not exists' % source_name))
   srcs = u', '.join([s.name for s in session.query(ArchiveSource).order_by(ArchiveSource.name)])
   if srcs:
    log.info((u'Known sources: %s' % srcs))
   return
  tags = []
  for tag_name in tag_names:
   tags.append(get_tag(tag_name, session))
  log.verbose((u'Please wait while adding tags %s ...' % u', '.join(tag_names)))
  for a in session.query(ArchiveEntry).filter(ArchiveEntry.sources.any(name=source_name)).yield_per(5):
   a.tags.extend(tags)
 finally:
  session.commit()
  session.close()

def tag_source ( source_name , tag_names = None ) : if ( ( not tag_names ) or ( tag_names is None ) ) : return session = Session ( ) try : source = session . query ( ArchiveSource ) . filter ( ( ArchiveSource . name == source_name ) ) . first ( ) if ( not source ) : log . critical ( ( u'Source `%s` does not exists' % source_name ) ) srcs = u', ' . join ( [ s . name for s in session . query ( ArchiveSource ) . order_by ( ArchiveSource . name ) ] ) if srcs : log . info ( ( u'Known sources: %s' % srcs ) ) return tags = [ ] for tag_name in tag_names : tags . append ( get_tag ( tag_name , session ) ) log . verbose ( ( u'Please wait while adding tags %s ...' % u', ' . join ( tag_names ) ) ) for a in session . query ( ArchiveEntry ) . filter ( ArchiveEntry . sources . any ( name = source_name ) ) . yield_per ( 5 ) : a . tags . extend ( tags ) finally : session . commit ( ) session . close ( )
tags all archived entries within a source with supplied tags .