~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/util.py

  • Committer: Michael Hudson
  • Date: 2008-02-27 03:36:09 UTC
  • mto: This revision was merged to the branch mainline in revision 146.
  • Revision ID: michael.hudson@canonical.com-20080227033609-6xz80buvasyekl6a
run reindent.py over the loggerhead package

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
                setattr(self, key, value)
106
106
        for key, value in kw.iteritems():
107
107
            setattr(self, key, value)
108
 
    
 
108
 
109
109
    def __repr__(self):
110
110
        out = '{ '
111
111
        for key, value in self.__dict__.iteritems():
160
160
        return '%s at %s' % (username, domains[-2])
161
161
    return '%s at %s' % (username, domains[0])
162
162
 
163
 
    
 
163
 
164
164
def triple_factors(min_value=1):
165
165
    factors = (1, 3)
166
166
    index = 0
178
178
    """
179
179
    given a position in a maximum range, return a list of negative and positive
180
180
    jump factors for an hgweb-style triple-factor geometric scan.
181
 
    
 
181
 
182
182
    for example, with pos=20 and max=500, the range would be:
183
183
    [ -10, -3, -1, 1, 3, 10, 30, 100, 300 ]
184
 
    
 
184
 
185
185
    i admit this is a very strange way of jumping through revisions.  i didn't
186
186
    invent it. :)
187
187
    """
289
289
        divisor = MEG
290
290
    else:
291
291
        divisor = KILO
292
 
    
 
292
 
293
293
    dot = size % divisor
294
294
    base = size - dot
295
295
    dot = dot * 10 // divisor
297
297
    if dot >= 10:
298
298
        base += 1
299
299
        dot -= 10
300
 
    
 
300
 
301
301
    out = str(base)
302
302
    if (base < 100) and (dot != 0):
303
303
        out += '.%d' % (dot,)
308
308
    elif divisor == GIG:
309
309
        out += 'G'
310
310
    return out
311
 
    
 
311
 
312
312
 
313
313
def fill_in_navigation(navigation):
314
314
    """
322
322
    navigation.count = len(navigation.revid_list)
323
323
    navigation.page_position = navigation.position // navigation.pagesize + 1
324
324
    navigation.page_count = (len(navigation.revid_list) + (navigation.pagesize - 1)) // navigation.pagesize
325
 
    
 
325
 
326
326
    def get_offset(offset):
327
327
        if (navigation.position + offset < 0) or (navigation.position + offset > navigation.count - 1):
328
328
            return None
329
329
        return navigation.revid_list[navigation.position + offset]
330
 
    
 
330
 
331
331
    navigation.prev_page_revid = get_offset(-1 * navigation.pagesize)
332
332
    navigation.next_page_revid = get_offset(1 * navigation.pagesize)
333
 
    
 
333
 
334
334
    params = { 'file_id': navigation.file_id }
335
335
    if getattr(navigation, 'query', None) is not None:
336
336
        params['q'] = navigation.query
337
337
    else:
338
338
        params['start_revid'] = navigation.start_revid
339
 
        
 
339
 
340
340
    if navigation.prev_page_revid:
341
341
        navigation.prev_page_url = navigation.branch.url([ navigation.scan_url, navigation.prev_page_revid ], **get_context(**params))
342
342
    if navigation.next_page_revid:
449
449
    """
450
450
    return a context map that may be overriden by specific values passed in,
451
451
    but only contains keys from the list of valid context keys.
452
 
    
 
452
 
453
453
    if 'clear' is set, only the 'remember' context value will be added, and
454
454
    all other context will be omitted.
455
455
    """