'This function should only be called from `agent.sync()`
method. It stores the results of terminated scans according to
the target status.'

def sync(self, agent):

    remout = agent.get_local_path('remoteoutput')
    for remfname in glob.glob(os.path.join(remout, (self.visiblecategory + '.*.xml'))):
        locfname = os.path.basename(remfname).split('.', 4)
        locfname[0] = self.category
        status = 'unknown'
        with open(remfname) as remfdesc:
            remfcontent = remfdesc.read()
            if ('<status    state="up"' in remfcontent):
                status = 'up'
            elif ('<status    state="down"' in remfcontent):
                if (not self.storedown):
                    remfdesc.close()
                    os.unlink(remfname)
                    continue
                status = 'down'
            del remfcontent
        locfname = os.path.join(self.outputpath, locfname[0], status, re.sub('[/@:]', '_', agent.name), *locfname[1:])
        utils.makedirs(os.path.dirname(locfname))
        os.rename(remfname, locfname)
