'Helper function for collect_jobs to build jobs for replication
using replication style storage policy'

def build_replication_jobs(self, policy, ips, override_devices=None, override_partitions=None):

    jobs = []
    df_mgr = self._df_router[policy]
    self.all_devs_info.update([(dev['replication_ip'], dev['device']) for dev in policy.object_ring.devs if dev])
    data_dir = get_data_dir(policy)
    found_local = False
    for local_dev in [dev for dev in policy.object_ring.devs if (dev and is_local_device(ips, self.port, dev['replication_ip'], dev['replication_port']) and ((override_devices is None) or (dev['device'] in override_devices)))]:
        found_local = True
        dev_path = join(self.devices_dir, local_dev['device'])
        obj_path = join(dev_path, data_dir)
        tmp_path = join(dev_path, get_tmp_dir(policy))
        if (self.mount_check and (not ismount(dev_path))):
            self._add_failure_stats([(failure_dev['replication_ip'], failure_dev['device']) for failure_dev in policy.object_ring.devs if failure_dev])
            self.logger.warning(_('%s    is    not    mounted'), local_dev['device'])
            continue
        unlink_older_than(tmp_path, (time.time() - df_mgr.reclaim_age))
        if (not os.path.exists(obj_path)):
            try:
                mkdirs(obj_path)
            except Exception:
                self.logger.exception(('ERROR    creating    %s' % obj_path))
            continue
        for partition in os.listdir(obj_path):
            if ((override_partitions is not None) and (partition not in override_partitions)):
                continue
            if (partition.startswith('auditor_status_') and partition.endswith('.json')):
                continue
            part_nodes = None
            try:
                job_path = join(obj_path, partition)
                part_nodes = policy.object_ring.get_part_nodes(int(partition))
                nodes = [node for node in part_nodes if (node['id'] != local_dev['id'])]
                jobs.append(dict(path=job_path, device=local_dev['device'], obj_path=obj_path, nodes=nodes, delete=(len(nodes) > (len(part_nodes) - 1)), policy=policy, partition=partition, region=local_dev['region']))
            except ValueError:
                if part_nodes:
                    self._add_failure_stats([(failure_dev['replication_ip'], failure_dev['device']) for failure_dev in nodes])
                else:
                    self._add_failure_stats([(failure_dev['replication_ip'], failure_dev['device']) for failure_dev in policy.object_ring.devs if failure_dev])
                continue
    if (not found_local):
        self.logger.error("Can't    find    itself    in    policy    with    index    %d    with    ips    %s    and    with    port    %s    in    ring    file,    not    replicating", int(policy), ',    '.join(ips), self.port)
    return jobs
