Merge lp:~therve/landscape-client/constants into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Approved by: Kevin McDermott
Approved revision: 269
Merged at revision: 269
Proposed branch: lp:~therve/landscape-client/constants
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 156 lines (+46/-31)
6 files modified
landscape/__init__.py (+9/-3)
landscape/constants.py (+28/-0)
landscape/lib/fetch.py (+1/-2)
landscape/monitor/aptpreferences.py (+2/-2)
landscape/package/changer.py (+5/-23)
landscape/upgraders/legacy.py (+1/-1)
To merge this branch: bzr merge lp:~therve/landscape-client/constants
Reviewer Review Type Date Requested Status
Kevin McDermott (community) Approve
Free Ekanayaka (community) Approve
Review via email: mp+28317@code.launchpad.net

Description of the change

Extract the 2 sets of used constants in a specific module, and make some general adjustments to reduce imports.

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Great! +1

review: Approve
Revision history for this message
Kevin McDermott (bigkevmcd) wrote :

Looks good to me, thanks for adding an actual date to remove the patch to initgroups :-)

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/__init__.py'
2--- landscape/__init__.py 2010-06-15 13:53:00 +0000
3+++ landscape/__init__.py 2010-06-23 18:35:33 +0000
4@@ -1,3 +1,5 @@
5+import sys
6+
7 DEBIAN_REVISION = ""
8 UPSTREAM_VERSION = "1.5.2"
9 VERSION = "%s%s" % (UPSTREAM_VERSION, DEBIAN_REVISION)
10@@ -46,6 +48,10 @@
11 from landscape.lib.initgroups import initgroups as cinitgroups
12 return cinitgroups(pwd.getpwuid(uid).pw_name, gid)
13
14-# Patch twisted initgroups implementation, which can result in very long calls
15-# to grp.getrlall(). See http://twistedmatrix.com/trac/ticket/3226
16-util.initgroups = initgroups
17+
18+if "twisted.python._initgroups" not in sys.modules:
19+ # Patch twisted initgroups implementation, which can result in very long
20+ # calls to grp.getrlall(). See http://twistedmatrix.com/trac/ticket/3226
21+ # We can remove that bit when Lucid is our oldest supported version
22+ # (May 2013).
23+ util.initgroups = initgroups
24
25=== added file 'landscape/constants.py'
26--- landscape/constants.py 1970-01-01 00:00:00 +0000
27+++ landscape/constants.py 2010-06-23 18:35:33 +0000
28@@ -0,0 +1,28 @@
29+"""
30+Hold constants used across landscape, to reduce import size when one only needs
31+to look at those values.
32+"""
33+
34+APT_PREFERENCES_SIZE_LIMIT = 1048576 # 1 MByte
35+
36+SUCCESS_RESULT = 1
37+ERROR_RESULT = 100
38+DEPENDENCY_ERROR_RESULT = 101
39+POLICY_STRICT = 0
40+POLICY_ALLOW_INSTALLS = 1
41+POLICY_ALLOW_ALL_CHANGES = 2
42+
43+# The amount of time to wait while we have unknown package data before
44+# reporting an error to the server in response to an operation.
45+# The two common cases of this are:
46+# 1. The server requested an operation that we've decided requires some
47+# dependencies, but we don't know the package ID of those dependencies. It
48+# should only take a bit more than 10 minutes for that to be resolved by the
49+# package reporter.
50+# 2. We lost some package data, for example by a deb archive becoming
51+# inaccessible for a while. The earliest we can reasonably assume that to be
52+# resolved is in 60 minutes, when the smart cronjob runs again.
53+
54+# So we'll give the problem one chance to resolve itself, by only waiting for
55+# one run of smart update.
56+UNKNOWN_PACKAGE_DATA_TIMEOUT = 70 * 60
57
58=== modified file 'landscape/lib/fetch.py'
59--- landscape/lib/fetch.py 2010-02-17 13:51:30 +0000
60+++ landscape/lib/fetch.py 2010-06-23 18:35:33 +0000
61@@ -4,8 +4,6 @@
62 from optparse import OptionParser
63 from StringIO import StringIO
64
65-import pycurl
66-
67 from twisted.internet.threads import deferToThread
68 from twisted.internet.defer import DeferredList
69
70@@ -56,6 +54,7 @@
71 on the request.
72 @param cainfo: Path to the file with CA certificates.
73 """
74+ import pycurl
75 output = StringIO(data)
76 input = StringIO()
77
78
79=== modified file 'landscape/monitor/aptpreferences.py'
80--- landscape/monitor/aptpreferences.py 2010-04-23 13:39:22 +0000
81+++ landscape/monitor/aptpreferences.py 2010-06-23 18:35:33 +0000
82@@ -1,9 +1,9 @@
83 import os
84
85+from landscape.constants import APT_PREFERENCES_SIZE_LIMIT
86+
87 from landscape.monitor.plugin import DataWatcher
88
89-APT_PREFERENCES_SIZE_LIMIT = 1048576 # 1 MByte
90-
91
92 class AptPreferences(DataWatcher):
93 """
94
95=== modified file 'landscape/package/changer.py'
96--- landscape/package/changer.py 2010-04-01 10:09:09 +0000
97+++ landscape/package/changer.py 2010-06-23 18:35:33 +0000
98@@ -8,6 +8,11 @@
99
100 from twisted.internet.defer import maybeDeferred, succeed
101
102+from landscape.constants import (
103+ SUCCESS_RESULT, ERROR_RESULT, DEPENDENCY_ERROR_RESULT, POLICY_STRICT,
104+ POLICY_ALLOW_INSTALLS, POLICY_ALLOW_ALL_CHANGES,
105+ UNKNOWN_PACKAGE_DATA_TIMEOUT)
106+
107 from landscape.lib.fs import create_file
108 from landscape.package.reporter import find_reporter_command
109 from landscape.package.taskhandler import (
110@@ -16,29 +21,6 @@
111 from landscape.manager.manager import SUCCEEDED
112
113
114-SUCCESS_RESULT = 1
115-ERROR_RESULT = 100
116-DEPENDENCY_ERROR_RESULT = 101
117-POLICY_STRICT = 0
118-POLICY_ALLOW_INSTALLS = 1
119-POLICY_ALLOW_ALL_CHANGES = 2
120-
121-# The amount of time to wait while we have unknown package data before
122-# reporting an error to the server in response to an operation.
123-# The two common cases of this are:
124-# 1. The server requested an operation that we've decided requires some
125-# dependencies, but we don't know the package ID of those dependencies. It
126-# should only take a bit more than 10 minutes for that to be resolved by the
127-# package reporter.
128-# 2. We lost some package data, for example by a deb archive becoming
129-# inaccessible for a while. The earliest we can reasonably assume that to be
130-# resolved is in 60 minutes, when the smart cronjob runs again.
131-
132-# So we'll give the problem one chance to resolve itself, by only waiting for
133-# one run of smart update.
134-UNKNOWN_PACKAGE_DATA_TIMEOUT = 70 * 60
135-
136-
137 class UnknownPackageData(Exception):
138 """Raised when an ID or a hash isn't known."""
139
140
141=== modified file 'landscape/upgraders/legacy.py'
142--- landscape/upgraders/legacy.py 2008-06-10 10:56:01 +0000
143+++ landscape/upgraders/legacy.py 2010-06-23 18:35:33 +0000
144@@ -1,5 +1,4 @@
145 import os
146-import gdbm
147
148 from landscape.patch import UpgradeManager
149 from landscape.lib.persist import Persist
150@@ -56,6 +55,7 @@
151
152 # package data needs to be migrated to a sqlite db
153 if os.path.exists(hashdb_filename):
154+ import gdbm
155 hashdb = gdbm.open(hashdb_filename, "r")
156 store = PackageStore(sqlite_filename)
157

Subscribers

People subscribed via source and target branches

to all changes: