Esempio n. 1
0
    def get_zippath(self, rawpath):
        """Generate a path for a file in a zip, given a path which may have
        bits which need escaping to be valid in a zip.

        """
        pathparts = rawpath.split('/')
        for i in xrange(len(pathparts)):
            fullpath = (i + 1 == len(pathparts))
            key = u'/'.join(pathparts[:i+1])
            zippath = self.rawpaths.get(key, None)
            if zippath is not None:
                continue

            # Generate new unique slug for the filename at this level
            zippath = self.rawpaths.get(u'/'.join(pathparts[:i]), '')
            if zippath != '':
                zippath += '/'
            if fullpath:
                path = pathparts[i].rsplit(u'.', 1)
                if len(path) == 2:
                    path, ext = path
                else:
                    path, ext = path[0], u''
                zippath += slugify(path)
                ext = u'.' + slugify(ext)
            else:
                zippath += slugify(pathparts[i])
                ext = u''
            if zippath + ext in self.zippaths:
                j = 1
                while True:
                    tmp = '%s_%d' % (zippath, j)
                    if tmp + ext not in self.zippaths:
                        zippath = tmp
                        break
                    j += 1
            zippath = zippath + ext

            self.zippaths.add(zippath)
            self.rawpaths[key] = zippath 
        return zippath
Esempio n. 2
0
    def gen_search_id(self, key):
        dictkey = dict(key)
        #print "Generating searchid for %r" % dictkey,
        searchid = []

        # First part of id is the collection
        collids = '_'.join(dictkey.get('collid', ()))
        if collids:
            searchid.append(collids)
        else:
            searchid.append('all')

        # Next part of id is the types
        ttypes = dictkey.get('ttypes')
        if ttypes is not None and len(ttypes) > 0:
            searchid.append('_'.join(sorted(ttypes)))
        else:
            searchid.append('all')

        # Next part of id is the search itself
        qs = dictkey.get('qs')
        if qs == ('1', ):
            # Add standard form of search
            q1f = dictkey.get('q1f')
            q1m = dictkey.get('q1m')
            if q1f and q1m:
                searchid.append(slugify(q1f[0].decode('utf8')).encode('utf8'))
                searchid.append(slugify(q1m[0].decode('utf8')).encode('utf8'))

        # Add showfull
        showfull = dictkey['showfull'][0]
        if showfull == 0:
            searchid.append('list')
        else:
            searchid.append('detail')

        # Add page id
        startrank = dictkey.get('startrank')
        if startrank is not None and len(startrank) > 0:
            startrank = int(startrank[0])
        else:
            startrank = 0
        if startrank == 0:
            searchid.append('index')
        else:
            searchid.append('from_%s' % startrank)

        searchid = '/'.join(searchid)

        if searchid is not None:
            # Check for any conflicting search (which could happen if we've
            # missed parameters).
            old = self.search_ids.get(searchid)
            if old is not None and old != key:
                searchid = None

        if searchid is None:
            # If we didn't generate an ID, generated a numeric ID.
            searchid = len(self.gen_searches) + 1

        #print "=%r" % searchid
        return searchid