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

Proposed by William Grant
Status: Merged
Approved by: Curtis Hovey
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 Approve
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.
Revision history for this message
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
=== removed file 'lib/canonical/launchpad/components/storm_operators.py'
--- lib/canonical/launchpad/components/storm_operators.py 2010-08-20 20:31:18 +0000
+++ lib/canonical/launchpad/components/storm_operators.py 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Operators and functions for Storm queries that are not in Storm.
5
6You can use these to do FTI queries like this:
7
8 >>> search_vector_column = <table.column>
9 >>> query_function = FTQ(search_term)
10 >>> rank = RANK(search_vector_column, query_function)
11 >>> select_spec = <required_columns, rank>
12 >>> results = store.find(
13 ... (select_spec),
14 ... Match(search_vector_column, query_function))
15 >>> results.order_by(Desc(rank))
16
17"""
18
19__metaclass__ = type
20
21__all__ = [
22 'FTQ',
23 'Match',
24 'RANK',
25 ]
26
27from storm.expr import (
28 CompoundOper,
29 NamedFunc,
30 )
31
32
33class FTQ(NamedFunc):
34 """Full Text Query function.
35
36 Implements the PostgreSQL ftq() function: ftq(search_string)
37 Returns a ts_query
38 """
39 __slots__ = ()
40 name = "FTQ"
41
42
43class RANK(NamedFunc):
44 """Full text rank function.
45
46 Implements the PostgreSQL ts_rank() function:
47 ts_rank(
48 [ weights float4[], ]
49 vector tsvector,
50 query tsquery [,
51 normalization integer ])
52
53 Returns a float4.
54 """
55 __slots__ = ()
56 name = "TS_RANK"
57
58
59class Match(CompoundOper):
60 """Full text match operator.
61
62 The full text match operator is used to compare a compiled search
63 (tsquery) expression to a text search vector (tsvector). In PostgreSQL, the
64 operator returns a "true" value if the tsvector matches the tsquery.
65 """
66 __slots__ = ()
67 oper = "@@"
68
690
=== modified file 'lib/canonical/launchpad/configure.zcml'
--- lib/canonical/launchpad/configure.zcml 2011-07-07 19:41:46 +0000
+++ lib/canonical/launchpad/configure.zcml 2011-09-14 01:26:41 +0000
@@ -12,7 +12,6 @@
1212
13 <include package="canonical.launchpad.webapp" />13 <include package="canonical.launchpad.webapp" />
14 <include package="canonical.launchpad.vocabularies" />14 <include package="canonical.launchpad.vocabularies" />
15 <include file="links.zcml" />
16 <include package="canonical.launchpad.zcml" />15 <include package="canonical.launchpad.zcml" />
17 <authorizations module="canonical.launchpad.security" />16 <authorizations module="canonical.launchpad.security" />
18 <include package="canonical.launchpad.xmlrpc" />17 <include package="canonical.launchpad.xmlrpc" />
1918
=== removed file 'lib/canonical/launchpad/datetimeutils.py'
--- lib/canonical/launchpad/datetimeutils.py 2010-08-20 20:31:18 +0000
+++ lib/canonical/launchpad/datetimeutils.py 1970-01-01 00:00:00 +0000
@@ -1,96 +0,0 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Various functions that are useful for handling dates/datetimes."""
5
6__metaclass__ = type
7
8from datetime import (
9 date,
10 timedelta,
11 )
12
13
14def make_mondays_between(start, end):
15 """Iteration of dates that are mondays between start and end dates.
16
17 A friday to a monday.
18
19 >>> for monday in make_mondays_between(
20 ... date(2005, 11, 25), date(2006, 1, 9)):
21 ... print monday.isocalendar()
22 (2005, 48, 1)
23 (2005, 49, 1)
24 (2005, 50, 1)
25 (2005, 51, 1)
26 (2005, 52, 1)
27 (2006, 1, 1)
28 (2006, 2, 1)
29
30 Test from Tuesday to Monday.
31
32 >>> for day in range(22, 30):
33 ... mondays = make_mondays_between(
34 ... date(2005, 11, day), date(2005, 12, day))
35 ... print date(2005, 11, day).isocalendar(), mondays.next().isoformat()
36 (2005, 47, 2) 2005-11-28
37 (2005, 47, 3) 2005-11-28
38 (2005, 47, 4) 2005-11-28
39 (2005, 47, 5) 2005-11-28
40 (2005, 47, 6) 2005-11-28
41 (2005, 47, 7) 2005-11-28
42 (2005, 48, 1) 2005-11-28
43 (2005, 48, 2) 2005-12-05
44 """
45 assert isinstance(start, date)
46 assert isinstance(end, date)
47 mondaystart = start + timedelta(days=(8 - start.isoweekday()) % 7)
48 currentdate = mondaystart
49 while currentdate <= end:
50 yield currentdate
51 currentdate += timedelta(days=7)
52
53def get_date_for_monday(year, week):
54 """Return the date of monday for the given iso week in the given year.
55
56 >>> get_date_for_monday(2005, 48).isoformat()
57 '2005-11-28'
58 >>> get_date_for_monday(2005, 50).isoformat()
59 '2005-12-12'
60 >>> get_date_for_monday(2005, 51).isoformat()
61 '2005-12-19'
62 >>> get_date_for_monday(2005, 52).isoformat()
63 '2005-12-26'
64 >>> get_date_for_monday(2005, 53).isoformat()
65 '2006-01-02'
66 >>> get_date_for_monday(2005, 54).isoformat()
67 '2006-01-09'
68 >>> get_date_for_monday(2006, 1).isoformat()
69 '2006-01-02'
70 >>> get_date_for_monday(2006, 2).isoformat()
71 '2006-01-09'
72 """
73 first_monday = first_monday_in_year(year)
74 fm_y, fm_w, fm_d = first_monday.isocalendar()
75 weeks_to_add = week - fm_w
76 assert weeks_to_add >= 0
77 return first_monday + timedelta(weeks=weeks_to_add)
78
79def first_monday_in_year(year):
80 """Return the date of the first monday in the year.
81
82 >>> for year in range(1999, 2009):
83 ... first_monday_in_year(year).isoformat()
84 '1999-01-04'
85 '2000-01-03'
86 '2001-01-01'
87 '2002-01-07'
88 '2003-01-06'
89 '2004-01-05'
90 '2005-01-03'
91 '2006-01-02'
92 '2007-01-01'
93 '2008-01-07'
94 """
95 return date(year, 1, (8 - date(year, 1, 1).isoweekday()) % 7 + 1)
96
970
=== modified file 'lib/canonical/launchpad/doc/helpers.txt'
--- lib/canonical/launchpad/doc/helpers.txt 2009-01-13 16:56:48 +0000
+++ lib/canonical/launchpad/doc/helpers.txt 2011-09-14 01:26:41 +0000
@@ -5,35 +5,6 @@
5duplicating code in different parts of Launchpad.5duplicating code in different parts of Launchpad.
66
77
8== Getting a valid name as our database asks for from a string ==
9
10 >>> from canonical.launchpad.helpers import getValidNameFromString
11
12The string has capital letters.
13
14 >>> original_string = 'EvilStringNotFollowingOurRules'
15 >>> getValidNameFromString(original_string)
16 'evilstringnotfollowingourrules'
17
18The string has underscores.
19
20 >>> original_string = 'evil_string_not_following_our_rules'
21 >>> getValidNameFromString(original_string)
22 'evil-string-not-following-our-rules'
23
24The string has white spaces.
25
26 >>> original_string = 'evil string not following our rules'
27 >>> getValidNameFromString(original_string)
28 'evil-string-not-following-our-rules'
29
30A mix of all previous cases.
31
32 >>> original_string = 'Evil String Not_Following_our rUles'
33 >>> getValidNameFromString(original_string)
34 'evil-string-not-following-our-rules'
35
36
37== Concatenating lists English-style ==8== Concatenating lists English-style ==
389
39The english_list function takes a list of strings and concatenates10The english_list function takes a list of strings and concatenates
4011
=== modified file 'lib/canonical/launchpad/helpers.py'
--- lib/canonical/launchpad/helpers.py 2011-06-08 05:43:21 +0000
+++ lib/canonical/launchpad/helpers.py 2011-09-14 01:26:41 +0000
@@ -12,7 +12,6 @@
1212
13from difflib import unified_diff13from difflib import unified_diff
14import os14import os
15import random
16import re15import re
17from StringIO import StringIO16from StringIO import StringIO
18import subprocess17import subprocess
@@ -95,83 +94,12 @@
95 return str.decode('UTF-8').encode('ASCII', 'backslashreplace')94 return str.decode('UTF-8').encode('ASCII', 'backslashreplace')
9695
9796
98def join_lines(*lines):
99 """Concatenate a list of strings, adding a newline at the end of each."""
100
101 return ''.join([x + '\n' for x in lines])
102
103
104def string_to_tarfile(s):97def string_to_tarfile(s):
105 """Convert a binary string containing a tar file into a tar file obj."""98 """Convert a binary string containing a tar file into a tar file obj."""
10699
107 return tarfile.open('', 'r', StringIO(s))100 return tarfile.open('', 'r', StringIO(s))
108101
109102
110def shortest(sequence):
111 """Return a list with the shortest items in sequence.
112
113 Return an empty list if the sequence is empty.
114 """
115 shortest_list = []
116 shortest_length = None
117
118 for item in list(sequence):
119 new_length = len(item)
120
121 if shortest_length is None:
122 # First item.
123 shortest_list.append(item)
124 shortest_length = new_length
125 elif new_length == shortest_length:
126 # Same length than shortest item found, we append it to the list.
127 shortest_list.append(item)
128 elif min(new_length, shortest_length) != shortest_length:
129 # Shorter than our shortest length found, discard old values.
130 shortest_list = [item]
131 shortest_length = new_length
132
133 return shortest_list
134
135
136def getRosettaBestBinaryPackageName(sequence):
137 """Return the best binary package name from a list.
138
139 It follows the Rosetta policy:
140
141 We don't need a concrete value from binary package name, we use shortest
142 function as a kind of heuristic to choose the shortest binary package
143 name that we suppose will be the more descriptive one for our needs with
144 PO templates. That's why we get always the first element.
145 """
146 return shortest(sequence)[0]
147
148
149def getRosettaBestDomainPath(sequence):
150 """Return the best path for a concrete .pot file from a list of paths.
151
152 It follows the Rosetta policy for this path:
153
154 We don't need a concrete value from domain_paths list, we use shortest
155 function as a kind of heuristic to choose the shortest path if we have
156 more than one, usually, we will have only one element.
157 """
158 return shortest(sequence)[0]
159
160
161def getValidNameFromString(invalid_name):
162 """Return a valid name based on a string.
163
164 A name in launchpad has a set of restrictions that not all strings follow.
165 This function converts any string in another one that follows our name
166 restriction rules.
167
168 To know more about all restrictions, please, look at valid_name function
169 in the database.
170 """
171 # All chars should be lower case, underscores and spaces become dashes.
172 return text_replaced(invalid_name.lower(), {'_': '-', ' ': '-'})
173
174
175def browserLanguages(request):103def browserLanguages(request):
176 """Return a list of Language objects based on the browser preferences."""104 """Return a list of Language objects based on the browser preferences."""
177 return IRequestPreferredLanguages(request).getPreferredLanguages()105 return IRequestPreferredLanguages(request).getPreferredLanguages()
@@ -214,36 +142,6 @@
214 for mail_person in get_recipients(person))142 for mail_person in get_recipients(person))
215143
216144
217replacements = {0: {'.': ' |dot| ',
218 '@': ' |at| '},
219 1: {'.': ' ! ',
220 '@': ' {} '},
221 2: {'.': ' , ',
222 '@': ' % '},
223 3: {'.': ' (!) ',
224 '@': ' (at) '},
225 4: {'.': ' {dot} ',
226 '@': ' {at} '},
227 }
228
229
230def obfuscateEmail(emailaddr, idx=None):
231 """Return an obfuscated version of the provided email address.
232
233 Randomly chose a set of replacements for some email address characters and
234 replace them. This will make harder for email harvesters to fetch email
235 address from launchpad.
236
237 >>> obfuscateEmail('foo@bar.com', 0)
238 'foo |at| bar |dot| com'
239 >>> obfuscateEmail('foo.bar@xyz.com.br', 1)
240 'foo ! bar {} xyz ! com ! br'
241 """
242 if idx is None:
243 idx = random.randint(0, len(replacements) - 1)
244 return text_replaced(emailaddr, replacements[idx])
245
246
247class ShortListTooBigError(Exception):145class ShortListTooBigError(Exception):
248 """This error is raised when the shortlist hardlimit is reached"""146 """This error is raised when the shortlist hardlimit is reached"""
249147
@@ -433,30 +331,6 @@
433 return 0331 return 0
434332
435333
436def positiveIntOrZero(value):
437 """Return 0 if int(value) fails or if int(value) is less than 0.
438
439 Return int(value) otherwise.
440
441 >>> positiveIntOrZero(None)
442 0
443 >>> positiveIntOrZero(-9)
444 0
445 >>> positiveIntOrZero(1)
446 1
447 >>> positiveIntOrZero('-3')
448 0
449 >>> positiveIntOrZero('5')
450 5
451 >>> positiveIntOrZero(3.1415)
452 3
453 """
454 value = intOrZero(value)
455 if value < 0:
456 return 0
457 return value
458
459
460def get_email_template(filename, app=None):334def get_email_template(filename, app=None):
461 """Returns the email template with the given file name.335 """Returns the email template with the given file name.
462336
463337
=== removed file 'lib/canonical/launchpad/links.zcml'
--- lib/canonical/launchpad/links.zcml 2009-07-13 18:15:02 +0000
+++ lib/canonical/launchpad/links.zcml 1970-01-01 00:00:00 +0000
@@ -1,7 +0,0 @@
1<!-- Copyright 2009 Canonical Ltd. This software is licensed under the
2 GNU Affero General Public License version 3 (see the file LICENSE).
3-->
4
5<configure xmlns:browser="http://namespaces.zope.org/browser">
6
7</configure>
80
=== removed file 'lib/canonical/launchpad/tests/test_datetimeutils.py'
--- lib/canonical/launchpad/tests/test_datetimeutils.py 2010-10-12 01:11:41 +0000
+++ lib/canonical/launchpad/tests/test_datetimeutils.py 1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4from doctest import DocTestSuite
5
6from canonical.launchpad import datetimeutils
7
8
9def test_suite():
10 return DocTestSuite(datetimeutils)
110
=== modified file 'lib/canonical/launchpad/tests/test_helpers.py'
--- lib/canonical/launchpad/tests/test_helpers.py 2011-03-30 20:08:42 +0000
+++ lib/canonical/launchpad/tests/test_helpers.py 2011-09-14 01:26:41 +0000
@@ -2,6 +2,7 @@
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4from doctest import DocTestSuite4from doctest import DocTestSuite
5from textwrap import dedent
5import unittest6import unittest
67
7from zope.interface import implements8from zope.interface import implements
@@ -67,17 +68,17 @@
67 '# Test PO file.\n'68 '# Test PO file.\n'
68 '''69 '''
6970
70 pot = helpers.join_lines(71 pot = dedent("""
71 '# Test POT file.',72 # Test POT file.
72 'msgid "foo"',73 msgid "foo"
73 'msgstr ""',74 msgstr ""
74 ),75 """).strip()
7576
76 po = helpers.join_lines(77 po = dedent("""
77 '# Test PO file.',78 # Test PO file.
78 'msgid "foo"',79 msgid "foo"
79 'msgstr "bar"',80 msgstr "bar"
80 )81 """).strip()
8182
82 return LaunchpadWriteTarFile.files_to_tarfile({83 return LaunchpadWriteTarFile.files_to_tarfile({
83 'test/test.pot': pot,84 'test/test.pot': pot,
@@ -86,22 +87,6 @@
86 })87 })
8788
8889
89def test_join_lines():
90 r"""
91 >>> helpers.join_lines('foo', 'bar', 'baz')
92 'foo\nbar\nbaz\n'
93 """
94
95
96def test_shortest():
97 """
98 >>> helpers.shortest(['xyzzy', 'foo', 'blah'])
99 ['foo']
100 >>> helpers.shortest(['xyzzy', 'foo', 'bar'])
101 ['foo', 'bar']
102 """
103
104
105class DummyLanguage:90class DummyLanguage:
10691
107 def __init__(self, code, pluralforms):92 def __init__(self, code, pluralforms):