Toggle a `badge_kind` for a given `path_or_id`

    The `path_or_id` is either an id, a slug or a file containing a list
    of ids or slugs.
425002
def toggle(path_or_id, badge_kind):
    '''
    '''
    if exists(path_or_id):
        with open(path_or_id) as open_file:
            for id_or_slug in open_file.readlines():
                toggle_badge(id_or_slug.strip(), badge_kind)
    else:
        toggle_badge(path_or_id, badge_kind)
708481
def remove_badge(self, kind):
        ''''''
        self.update(__raw__={
            '$pull': {
                'badges': {'kind': kind}
            }
        })
        self.reload()
        on_badge_removed.send(self, kind=kind)
        post_save.send(self.__class__, document=self)
118372
def save_id_to_path_mapping(self):
    
    if not self.id_to_path_mapping:
      return
    with open(self.local_id_to_path_mapping_file, 'w') as f:
      writer = csv.writer(f)
      writer.writerow(['id', 'path'])
      for k, v in sorted(iteritems(self.id_to_path_mapping)):
        writer.writerow([k, v])
    cmd = ['gsutil', 'cp', self.local_id_to_path_mapping_file,
           os.path.join(self.target_dir, 'id_to_path_mapping.csv')]
    if subprocess.call(cmd) != 0:
      logging.error('Can\'t copy id_to_path_mapping.csv to target directory')
1164730
def strip_path_session_id(path):
    ''''''
    for pattern in SESSION_ID_PATH_PATTERNS:
        match = pattern.match(path)
        if match:
            path = match.group(1) + match.group(3)

    return path
2331
function is_addon_connected( $id_or_slug ) {
            $this->_logger->entrance();

            $sites = self::get_all_sites( WP_FS__MODULE_TYPE_PLUGIN );

            $addon_id = self::get_module_id( $id_or_slug );
            $addon    = $this->get_addon( $addon_id );
            $slug     = $addon->slug;
            if ( ! isset( $sites[ $slug ] ) ) {
                return false;
            }

            $site = $sites[ $slug ];

            $plugin = FS_Plugin_Manager::instance( $addon_id )->get();

            if ( $plugin->parent_plugin_id != $this->_plugin->id ) {
                // The given slug do NOT belong to any of the plugin's add-ons.
                return false;
            }

            return ( is_object( $site ) &&
                     is_numeric( $site->id ) &&
                     is_numeric( $site->user_id ) &&
                     FS_Plugin_Plan::is_valid_id( $site->plan_id )
            );
        }
266210
def create_id2collection_info(path, tag):
    
    d = {}
    for triple in os.walk(path):
        root, files = triple[0], triple[2]
        for filename in files:
            if filename.endswith('.json'):
                # trim file extension and prepend owner_id (from path)
                collection_id = "{u}/{n}".format(u=root.split('/')[-1], n=filename[:-5])
                d[collection_id] = (tag, root, os.path.join(root, filename))
    return d
161001
function(filePath){
  var parts = filePath.split('/');
  if(parts.length > 0){
    var id = parts.pop();
    return {
      id: id,
      path: parts.join('/')
    }
  } else {
    return false;
  }
}
497570
def file_or_folder(path):
        
        target = unicode(path)
        return Folder(target) if os.path.isdir(target) else File(target)
988979
function linkedIds(resource, linksKey) {
    return _.compact(_.flatten(_.map(resource, function(obj) {
      return obj.links && obj.links[linksKey];
    })));
  }
1265330
def build_uri(self, id_or_uri):
        
        if not id_or_uri:
            logger.exception(RESOURCE_CLIENT_INVALID_ID)
            raise ValueError(RESOURCE_CLIENT_INVALID_ID)

        if "/" in id_or_uri:
            self.validate_resource_uri(id_or_uri)
            return id_or_uri
        else:
            return self._base_uri + "/" + id_or_uri
536801
public static boolean hasPathAsItemId(Container cnt, String path) {

        return cnt.containsId(path) || cnt.containsId(CmsFileUtil.toggleTrailingSeparator(path));
    }
370101
def get_category_or_404(path):
    
    path_bits = [p for p in path.split('/') if p]
    return get_object_or_404(Category, slug=path_bits[-1])
98481
def find(path, id, params = {})
      response = get("/#{path.to_s.pluralize}/#{id}", params)
      trello_class = class_from_path(path)
      trello_class.parse response do |data|
        data.client = self
      end
    end
749636
def thing_path(model, object)
      id = object['ID'] || object['id']
      send(:"admin_#{undersingularize(model)}_path", id: id)
    end
1340782
def get_drives(self, id_or_uri):
        
        uri = self._client.build_uri(id_or_uri=id_or_uri) + self.DRIVES_PATH
        return self._client.get(id_or_uri=uri)
25758
def is_path_like(obj, attr=('name', 'is_file', 'is_dir', 'iterdir')):
    """"""
    for a in attr:
        if not hasattr(obj, a):
            return False
    return True
388716
private String pathToItem(String id) {
		return subDirForId(id) + UNIX_PATH_SEPERATOR + id.substring(SUBDIR_POLICY);
	}