'Archives (when `unarchive` is True, unarchives) a given
host record. Also (un)archives the corresponding scan and
removes the scan from the "not archived" (or "archived") scan
collection if not there is no host left in the "not archived"
(or "archived") host collumn.'

def archive(self, host, unarchive=False):

    (col_from_hosts, col_from_scans, col_to_hosts, col_to_scans) = ((self.colname_oldhosts, self.colname_oldscans, self.colname_hosts, self.colname_scans) if unarchive else (self.colname_hosts, self.colname_scans, self.colname_oldhosts, self.colname_oldscans))
    if (self.find_one(col_from_hosts, {'_id': host['_id']}) is None):
        utils.LOGGER.warning('Cannot    %sarchive:    host    %s    does    not    exist    in    %r', ('un' if unarchive else ''), host['_id'], col_from_hosts)
    self.db[col_to_hosts].insert(host)
    utils.LOGGER.debug('HOST    %sARCHIVED:    %s    in    %r', ('UN' if unarchive else ''), host['_id'], col_to_hosts)
    self.db[col_from_hosts].remove(spec_or_id=host['_id'])
    utils.LOGGER.debug('HOST    REMOVED:    %s    from    %r', host['_id'], col_from_hosts)
    for scanid in self.getscanids(host):
        scan = self.find_one(col_from_scans, {'_id': scanid})
        if (scan is not None):
            if (self.find_one(col_to_scans, {'_id': scanid}) is None):
                self.db[col_to_scans].insert(scan)
                utils.LOGGER.debug('SCAN    %sARCHIVED:    %s    in    %r\n', ('UN' if unarchive else ''), scanid, col_to_scans)
            if (self.find_one(col_from_hosts, {'scanid': scanid}) is None):
                self.db[col_from_scans].remove(spec_or_id=scanid)
                utils.LOGGER.debug('SCAN    REMOVED:    %s    in    %r', scanid, col_from_scans)
