Merge lp:~wgrant/launchpad/delete-more into lp:launchpad

Proposed by William Grant on 2011-09-13
Status: Merged
Approved by: Curtis Hovey on 2011-09-13
Approved revision: no longer in the source branch.
Merged at revision: 13950
Proposed branch: lp:~wgrant/launchpad/delete-more
Merge into: lp:launchpad
Diff against target: 479 lines (+11/-363)
8 files modified
lib/canonical/launchpad/components/storm_operators.py (+0/-68)
lib/canonical/launchpad/configure.zcml (+0/-1)
lib/canonical/launchpad/datetimeutils.py (+0/-96)
lib/canonical/launchpad/doc/helpers.txt (+0/-29)
lib/canonical/launchpad/helpers.py (+0/-126)
lib/canonical/launchpad/links.zcml (+0/-7)
lib/canonical/launchpad/tests/test_datetimeutils.py (+0/-10)
lib/canonical/launchpad/tests/test_helpers.py (+11/-26)
To merge this branch: bzr merge lp:~wgrant/launchpad/delete-more
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code 2011-09-13 Approve on 2011-09-13
Review via email: mp+75179@code.launchpad.net

Commit message

[r=sinzui][no-qa] Delete some unused code from canonical.*.

Description of the change

Delete some unused code from canonical.*.

To post a comment you must log in.
Curtis Hovey (sinzui) wrote :

Thank you very much!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed file 'lib/canonical/launchpad/components/storm_operators.py'
2--- lib/canonical/launchpad/components/storm_operators.py 2010-08-20 20:31:18 +0000
3+++ lib/canonical/launchpad/components/storm_operators.py 1970-01-01 00:00:00 +0000
4@@ -1,68 +0,0 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6-# GNU Affero General Public License version 3 (see the file LICENSE).
7-
8-"""Operators and functions for Storm queries that are not in Storm.
9-
10-You can use these to do FTI queries like this:
11-
12- >>> search_vector_column = <table.column>
13- >>> query_function = FTQ(search_term)
14- >>> rank = RANK(search_vector_column, query_function)
15- >>> select_spec = <required_columns, rank>
16- >>> results = store.find(
17- ... (select_spec),
18- ... Match(search_vector_column, query_function))
19- >>> results.order_by(Desc(rank))
20-
21-"""
22-
23-__metaclass__ = type
24-
25-__all__ = [
26- 'FTQ',
27- 'Match',
28- 'RANK',
29- ]
30-
31-from storm.expr import (
32- CompoundOper,
33- NamedFunc,
34- )
35-
36-
37-class FTQ(NamedFunc):
38- """Full Text Query function.
39-
40- Implements the PostgreSQL ftq() function: ftq(search_string)
41- Returns a ts_query
42- """
43- __slots__ = ()
44- name = "FTQ"
45-
46-
47-class RANK(NamedFunc):
48- """Full text rank function.
49-
50- Implements the PostgreSQL ts_rank() function:
51- ts_rank(
52- [ weights float4[], ]
53- vector tsvector,
54- query tsquery [,
55- normalization integer ])
56-
57- Returns a float4.
58- """
59- __slots__ = ()
60- name = "TS_RANK"
61-
62-
63-class Match(CompoundOper):
64- """Full text match operator.
65-
66- The full text match operator is used to compare a compiled search
67- (tsquery) expression to a text search vector (tsvector). In PostgreSQL, the
68- operator returns a "true" value if the tsvector matches the tsquery.
69- """
70- __slots__ = ()
71- oper = "@@"
72-
73
74=== modified file 'lib/canonical/launchpad/configure.zcml'
75--- lib/canonical/launchpad/configure.zcml 2011-07-07 19:41:46 +0000
76+++ lib/canonical/launchpad/configure.zcml 2011-09-14 01:26:41 +0000
77@@ -12,7 +12,6 @@
78
79 <include package="canonical.launchpad.webapp" />
80 <include package="canonical.launchpad.vocabularies" />
81- <include file="links.zcml" />
82 <include package="canonical.launchpad.zcml" />
83 <authorizations module="canonical.launchpad.security" />
84 <include package="canonical.launchpad.xmlrpc" />
85
86=== removed file 'lib/canonical/launchpad/datetimeutils.py'
87--- lib/canonical/launchpad/datetimeutils.py 2010-08-20 20:31:18 +0000
88+++ lib/canonical/launchpad/datetimeutils.py 1970-01-01 00:00:00 +0000
89@@ -1,96 +0,0 @@
90-# Copyright 2009 Canonical Ltd. This software is licensed under the
91-# GNU Affero General Public License version 3 (see the file LICENSE).
92-
93-"""Various functions that are useful for handling dates/datetimes."""
94-
95-__metaclass__ = type
96-
97-from datetime import (
98- date,
99- timedelta,
100- )
101-
102-
103-def make_mondays_between(start, end):
104- """Iteration of dates that are mondays between start and end dates.
105-
106- A friday to a monday.
107-
108- >>> for monday in make_mondays_between(
109- ... date(2005, 11, 25), date(2006, 1, 9)):
110- ... print monday.isocalendar()
111- (2005, 48, 1)
112- (2005, 49, 1)
113- (2005, 50, 1)
114- (2005, 51, 1)
115- (2005, 52, 1)
116- (2006, 1, 1)
117- (2006, 2, 1)
118-
119- Test from Tuesday to Monday.
120-
121- >>> for day in range(22, 30):
122- ... mondays = make_mondays_between(
123- ... date(2005, 11, day), date(2005, 12, day))
124- ... print date(2005, 11, day).isocalendar(), mondays.next().isoformat()
125- (2005, 47, 2) 2005-11-28
126- (2005, 47, 3) 2005-11-28
127- (2005, 47, 4) 2005-11-28
128- (2005, 47, 5) 2005-11-28
129- (2005, 47, 6) 2005-11-28
130- (2005, 47, 7) 2005-11-28
131- (2005, 48, 1) 2005-11-28
132- (2005, 48, 2) 2005-12-05
133- """
134- assert isinstance(start, date)
135- assert isinstance(end, date)
136- mondaystart = start + timedelta(days=(8 - start.isoweekday()) % 7)
137- currentdate = mondaystart
138- while currentdate <= end:
139- yield currentdate
140- currentdate += timedelta(days=7)
141-
142-def get_date_for_monday(year, week):
143- """Return the date of monday for the given iso week in the given year.
144-
145- >>> get_date_for_monday(2005, 48).isoformat()
146- '2005-11-28'
147- >>> get_date_for_monday(2005, 50).isoformat()
148- '2005-12-12'
149- >>> get_date_for_monday(2005, 51).isoformat()
150- '2005-12-19'
151- >>> get_date_for_monday(2005, 52).isoformat()
152- '2005-12-26'
153- >>> get_date_for_monday(2005, 53).isoformat()
154- '2006-01-02'
155- >>> get_date_for_monday(2005, 54).isoformat()
156- '2006-01-09'
157- >>> get_date_for_monday(2006, 1).isoformat()
158- '2006-01-02'
159- >>> get_date_for_monday(2006, 2).isoformat()
160- '2006-01-09'
161- """
162- first_monday = first_monday_in_year(year)
163- fm_y, fm_w, fm_d = first_monday.isocalendar()
164- weeks_to_add = week - fm_w
165- assert weeks_to_add >= 0
166- return first_monday + timedelta(weeks=weeks_to_add)
167-
168-def first_monday_in_year(year):
169- """Return the date of the first monday in the year.
170-
171- >>> for year in range(1999, 2009):
172- ... first_monday_in_year(year).isoformat()
173- '1999-01-04'
174- '2000-01-03'
175- '2001-01-01'
176- '2002-01-07'
177- '2003-01-06'
178- '2004-01-05'
179- '2005-01-03'
180- '2006-01-02'
181- '2007-01-01'
182- '2008-01-07'
183- """
184- return date(year, 1, (8 - date(year, 1, 1).isoweekday()) % 7 + 1)
185-
186
187=== modified file 'lib/canonical/launchpad/doc/helpers.txt'
188--- lib/canonical/launchpad/doc/helpers.txt 2009-01-13 16:56:48 +0000
189+++ lib/canonical/launchpad/doc/helpers.txt 2011-09-14 01:26:41 +0000
190@@ -5,35 +5,6 @@
191 duplicating code in different parts of Launchpad.
192
193
194-== Getting a valid name as our database asks for from a string ==
195-
196- >>> from canonical.launchpad.helpers import getValidNameFromString
197-
198-The string has capital letters.
199-
200- >>> original_string = 'EvilStringNotFollowingOurRules'
201- >>> getValidNameFromString(original_string)
202- 'evilstringnotfollowingourrules'
203-
204-The string has underscores.
205-
206- >>> original_string = 'evil_string_not_following_our_rules'
207- >>> getValidNameFromString(original_string)
208- 'evil-string-not-following-our-rules'
209-
210-The string has white spaces.
211-
212- >>> original_string = 'evil string not following our rules'
213- >>> getValidNameFromString(original_string)
214- 'evil-string-not-following-our-rules'
215-
216-A mix of all previous cases.
217-
218- >>> original_string = 'Evil String Not_Following_our rUles'
219- >>> getValidNameFromString(original_string)
220- 'evil-string-not-following-our-rules'
221-
222-
223 == Concatenating lists English-style ==
224
225 The english_list function takes a list of strings and concatenates
226
227=== modified file 'lib/canonical/launchpad/helpers.py'
228--- lib/canonical/launchpad/helpers.py 2011-06-08 05:43:21 +0000
229+++ lib/canonical/launchpad/helpers.py 2011-09-14 01:26:41 +0000
230@@ -12,7 +12,6 @@
231
232 from difflib import unified_diff
233 import os
234-import random
235 import re
236 from StringIO import StringIO
237 import subprocess
238@@ -95,83 +94,12 @@
239 return str.decode('UTF-8').encode('ASCII', 'backslashreplace')
240
241
242-def join_lines(*lines):
243- """Concatenate a list of strings, adding a newline at the end of each."""
244-
245- return ''.join([x + '\n' for x in lines])
246-
247-
248 def string_to_tarfile(s):
249 """Convert a binary string containing a tar file into a tar file obj."""
250
251 return tarfile.open('', 'r', StringIO(s))
252
253
254-def shortest(sequence):
255- """Return a list with the shortest items in sequence.
256-
257- Return an empty list if the sequence is empty.
258- """
259- shortest_list = []
260- shortest_length = None
261-
262- for item in list(sequence):
263- new_length = len(item)
264-
265- if shortest_length is None:
266- # First item.
267- shortest_list.append(item)
268- shortest_length = new_length
269- elif new_length == shortest_length:
270- # Same length than shortest item found, we append it to the list.
271- shortest_list.append(item)
272- elif min(new_length, shortest_length) != shortest_length:
273- # Shorter than our shortest length found, discard old values.
274- shortest_list = [item]
275- shortest_length = new_length
276-
277- return shortest_list
278-
279-
280-def getRosettaBestBinaryPackageName(sequence):
281- """Return the best binary package name from a list.
282-
283- It follows the Rosetta policy:
284-
285- We don't need a concrete value from binary package name, we use shortest
286- function as a kind of heuristic to choose the shortest binary package
287- name that we suppose will be the more descriptive one for our needs with
288- PO templates. That's why we get always the first element.
289- """
290- return shortest(sequence)[0]
291-
292-
293-def getRosettaBestDomainPath(sequence):
294- """Return the best path for a concrete .pot file from a list of paths.
295-
296- It follows the Rosetta policy for this path:
297-
298- We don't need a concrete value from domain_paths list, we use shortest
299- function as a kind of heuristic to choose the shortest path if we have
300- more than one, usually, we will have only one element.
301- """
302- return shortest(sequence)[0]
303-
304-
305-def getValidNameFromString(invalid_name):
306- """Return a valid name based on a string.
307-
308- A name in launchpad has a set of restrictions that not all strings follow.
309- This function converts any string in another one that follows our name
310- restriction rules.
311-
312- To know more about all restrictions, please, look at valid_name function
313- in the database.
314- """
315- # All chars should be lower case, underscores and spaces become dashes.
316- return text_replaced(invalid_name.lower(), {'_': '-', ' ': '-'})
317-
318-
319 def browserLanguages(request):
320 """Return a list of Language objects based on the browser preferences."""
321 return IRequestPreferredLanguages(request).getPreferredLanguages()
322@@ -214,36 +142,6 @@
323 for mail_person in get_recipients(person))
324
325
326-replacements = {0: {'.': ' |dot| ',
327- '@': ' |at| '},
328- 1: {'.': ' ! ',
329- '@': ' {} '},
330- 2: {'.': ' , ',
331- '@': ' % '},
332- 3: {'.': ' (!) ',
333- '@': ' (at) '},
334- 4: {'.': ' {dot} ',
335- '@': ' {at} '},
336- }
337-
338-
339-def obfuscateEmail(emailaddr, idx=None):
340- """Return an obfuscated version of the provided email address.
341-
342- Randomly chose a set of replacements for some email address characters and
343- replace them. This will make harder for email harvesters to fetch email
344- address from launchpad.
345-
346- >>> obfuscateEmail('foo@bar.com', 0)
347- 'foo |at| bar |dot| com'
348- >>> obfuscateEmail('foo.bar@xyz.com.br', 1)
349- 'foo ! bar {} xyz ! com ! br'
350- """
351- if idx is None:
352- idx = random.randint(0, len(replacements) - 1)
353- return text_replaced(emailaddr, replacements[idx])
354-
355-
356 class ShortListTooBigError(Exception):
357 """This error is raised when the shortlist hardlimit is reached"""
358
359@@ -433,30 +331,6 @@
360 return 0
361
362
363-def positiveIntOrZero(value):
364- """Return 0 if int(value) fails or if int(value) is less than 0.
365-
366- Return int(value) otherwise.
367-
368- >>> positiveIntOrZero(None)
369- 0
370- >>> positiveIntOrZero(-9)
371- 0
372- >>> positiveIntOrZero(1)
373- 1
374- >>> positiveIntOrZero('-3')
375- 0
376- >>> positiveIntOrZero('5')
377- 5
378- >>> positiveIntOrZero(3.1415)
379- 3
380- """
381- value = intOrZero(value)
382- if value < 0:
383- return 0
384- return value
385-
386-
387 def get_email_template(filename, app=None):
388 """Returns the email template with the given file name.
389
390
391=== removed file 'lib/canonical/launchpad/links.zcml'
392--- lib/canonical/launchpad/links.zcml 2009-07-13 18:15:02 +0000
393+++ lib/canonical/launchpad/links.zcml 1970-01-01 00:00:00 +0000
394@@ -1,7 +0,0 @@
395-<!-- Copyright 2009 Canonical Ltd. This software is licensed under the
396- GNU Affero General Public License version 3 (see the file LICENSE).
397--->
398-
399-<configure xmlns:browser="http://namespaces.zope.org/browser">
400-
401-</configure>
402
403=== removed file 'lib/canonical/launchpad/tests/test_datetimeutils.py'
404--- lib/canonical/launchpad/tests/test_datetimeutils.py 2010-10-12 01:11:41 +0000
405+++ lib/canonical/launchpad/tests/test_datetimeutils.py 1970-01-01 00:00:00 +0000
406@@ -1,10 +0,0 @@
407-# Copyright 2009 Canonical Ltd. This software is licensed under the
408-# GNU Affero General Public License version 3 (see the file LICENSE).
409-
410-from doctest import DocTestSuite
411-
412-from canonical.launchpad import datetimeutils
413-
414-
415-def test_suite():
416- return DocTestSuite(datetimeutils)
417
418=== modified file 'lib/canonical/launchpad/tests/test_helpers.py'
419--- lib/canonical/launchpad/tests/test_helpers.py 2011-03-30 20:08:42 +0000
420+++ lib/canonical/launchpad/tests/test_helpers.py 2011-09-14 01:26:41 +0000
421@@ -2,6 +2,7 @@
422 # GNU Affero General Public License version 3 (see the file LICENSE).
423
424 from doctest import DocTestSuite
425+from textwrap import dedent
426 import unittest
427
428 from zope.interface import implements
429@@ -67,17 +68,17 @@
430 '# Test PO file.\n'
431 '''
432
433- pot = helpers.join_lines(
434- '# Test POT file.',
435- 'msgid "foo"',
436- 'msgstr ""',
437- ),
438+ pot = dedent("""
439+ # Test POT file.
440+ msgid "foo"
441+ msgstr ""
442+ """).strip()
443
444- po = helpers.join_lines(
445- '# Test PO file.',
446- 'msgid "foo"',
447- 'msgstr "bar"',
448- )
449+ po = dedent("""
450+ # Test PO file.
451+ msgid "foo"
452+ msgstr "bar"
453+ """).strip()
454
455 return LaunchpadWriteTarFile.files_to_tarfile({
456 'test/test.pot': pot,
457@@ -86,22 +87,6 @@
458 })
459
460
461-def test_join_lines():
462- r"""
463- >>> helpers.join_lines('foo', 'bar', 'baz')
464- 'foo\nbar\nbaz\n'
465- """
466-
467-
468-def test_shortest():
469- """
470- >>> helpers.shortest(['xyzzy', 'foo', 'blah'])
471- ['foo']
472- >>> helpers.shortest(['xyzzy', 'foo', 'bar'])
473- ['foo', 'bar']
474- """
475-
476-
477 class DummyLanguage:
478
479 def __init__(self, code, pluralforms):