Remove remotes with 'review' prefix (left over from previous reviews).
 Prune all existing remotes and delete obsolete branches (left over from
 already closed requests).
181230
def clean(number = nil, force = false, all = false)
      git_call "checkout #{local.target_branch}"
      local.prune_remotes
      # Determine strategy to clean.
      if all
        local.clean_all
      else
        local.clean_single(number, force)
      end
      # Remove al review remotes without existing local branches.
      local.clean_remotes
    end
679829
def cleanup(self):
        
        if self.local_port is not None:
            logger.debug(("Stopping ssh tunnel {0}:{1}:{2} for "
                          "{3}@{4}".format(self.local_port,
                                           self.remote_address,
                                           self.remote_port,
                                           self.username,
                                           self.address)))
            if self.forward is not None:
                self.forward.stop()
                self.forward.join()
            if self.transport is not None:
                self.transport.close()
602904
def cleanup(self):
        
        pb = self._get_ansible_playbook(self.playbooks.cleanup)
        pb.execute()
171222
public void cleanup() {
        synchronized (_sslMap) {
            for (SslRelayOdo relay : _sslMap.values()) {
                if (relay.getHttpServer() != null && relay.isStarted()) {
                    relay.getHttpServer().removeListener(relay);
                }
            }

            sslRelays.clear();
        }
    }
300787
def clear_old_remotes(self):
        '''
        
        '''
        try:
            cachedir_ls = os.listdir(self.cache_root)
        except OSError:
            cachedir_ls = []
        # Remove actively-used remotes from list
        for repo in self.remotes:
            try:
                cachedir_ls.remove(repo.cachedir_basename)
            except ValueError:
                pass
        to_remove = []
        for item in cachedir_ls:
            if item in ('hash', 'refs'):
                continue
            path = salt.utils.path.join(self.cache_root, item)
            if os.path.isdir(path):
                to_remove.append(path)
        failed = []
        if to_remove:
            for rdir in to_remove:
                try:
                    shutil.rmtree(rdir)
                except OSError as exc:
                    log.error(
                        'Unable to remove old %s remote cachedir %s: %s',
                        self.role, rdir, exc
                    )
                    failed.append(rdir)
                else:
                    log.debug('%s removed old cachedir %s', self.role, rdir)
        for fdir in failed:
            to_remove.remove(fdir)
        ret = bool(to_remove)
        if ret:
            self.write_remote_map()
        return ret
910152
def _cleanupConnections(senderkey, signal):
    """"""
    try:
        receivers = connections[senderkey][signal]
    except:
        pass
    else:
        if not receivers:
            # No more connected receivers. Therefore, remove the signal.
            try:
                signals = connections[senderkey]
            except KeyError:
                pass
            else:
                del signals[signal]
                if not signals:
                    # No more signal connections. Therefore, remove the sender.
                    _removeSender(senderkey)
51113
def purge_old(self):
        '''
        
        '''
        if self.keep_max is not None:
            keys = self.redis_conn.keys(self.get_key() + ':*')
            keys.sort(reverse=True)
            while len(keys) > self.keep_max:
                key = keys.pop()
                self.redis_conn.delete(key)
955729
def teardown(self):
        ''''''

        self.ensure_all_devices_in_sync()
        for device in self.devices:
            self._delete_device_from_device_group(device)
            self._sync_to_group(device)
            pollster(self._ensure_device_active)(device)
            self.ensure_all_devices_in_sync()
        dg = pollster(self._get_device_group)(self.devices[0])
        dg.delete()
        pollster(self._check_devices_active_licensed)()
        pollster(self._check_all_devices_in_sync)()
75365
def _clean_item(self, request_url):
        
        del self._table[request_url]
        self._usage_recency.remove(request_url)
1137315
def git_remotes
      remotes = {}
      @git.git.remote.split.each do |remote|
        url = @git.git.config({}, '--get', "remote.#{remote}.url").strip
        remotes[remote] = Remote::Git.new(self, remote, url)
      end
      remotes
    end
510252
def prune_old_authorization_codes():
    

    from .compat import now
    from .models import AuthorizationCode
    
    AuthorizationCode.objects.with_expiration_before(now()).delete()
273354
def clean_stale_refs(self, local_refs=None):  # pylint: disable=arguments-differ
        '''
        
        '''
        try:
            if pygit2.GIT_FETCH_PRUNE:
                # Don't need to clean anything, pygit2 can do it by itself
                return []
        except AttributeError:
            # However, only in 0.26.2 and newer
            pass
        if self.credentials is not None:
            log.debug(
                'The installed version of pygit2 (%s) does not support '
                'detecting stale refs for authenticated remotes, saltenvs '
                'will not reflect branches/tags removed from remote \'%s\'',
                PYGIT2_VERSION, self.id
            )
            return []
        return super(Pygit2, self).clean_stale_refs()
131381
def clean_single(number, force = false)
      request = server.pull_request(source_repo, number)
      if request && request.state == 'closed'
        # ensure there are no unmerged commits or '--force' flag has been set
        branch_name = request.head.ref
        if unmerged_commits?(branch_name) && !force
          puts "Won't delete branches that contain unmerged commits."
          puts "Use '--force' to override."
        else
          delete_branch(branch_name)
        end
      end
    rescue Octokit::NotFound
      false
    end
920355
def cleanup_repo(self):
        """"""
        if self.source and path.isdir(self.source):
            self.log.debug('Cleaning up source repo from %s', self.source)
            shutil.rmtree(self.source)
573675
def cleanup_candidates(self, node_ip):
        
        if node_ip in self.factory.candidates:
            old_candidates = []
            for candidate in self.factory.candidates[node_ip]:
                elapsed = int(time.time() - candidate["time"])
                if elapsed > self.challege_timeout:
                    old_candidates.append(candidate)

            for candidate in old_candidates:
                self.factory.candidates[node_ip].remove(candidate)
535491
def do_removerep(self, line):
        """"""
        mns = self._split_args(line, 1, -1)
        self._command_processor.get_session().get_replication_policy().repremove(mns)
        self._print_info_if_verbose(
            "Removed {} from replication policy".format(", ".join(mns))
        )
1288359
def delete_commit_branches(self, enrich_backend):
        
        fltr = """
            "filter": [
                {
                    "term": {
                        "origin": "%s"
                    }
                }
            ]
        """ % self.perceval_backend.origin

        # reset references in enrich index
        es_query = """
            {
              "script": {
                "source": "ctx._source.branches = new HashSet();",
                "lang": "painless"
              },
              "query": {
                "bool": {
                    %s
                }
              }
            }
            """ % fltr

        index = enrich_backend.elastic.index_url
        r = self.requests.post(index + "/_update_by_query?refresh", data=es_query, headers=HEADER_JSON, verify=False)
        try:
            r.raise_for_status()
        except requests.exceptions.HTTPError:
            logger.error("Error while deleting branches on %s",
                         self.elastic.anonymize_url(index))
            logger.error(r.text)
            return

        logger.debug("Delete branches %s, index %s", r.text, self.elastic.anonymize_url(index))