Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 192bd96

Browse files
committed
getDefaultDatabase() should be a toplevel function, not a method of the
preferences object.
1 parent afd63b9 commit 192bd96

1 file changed

Lines changed: 46 additions & 48 deletions

File tree

Lib/plat-mac/pimp.py

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,51 @@
4646
DEFAULT_INSTALLDIR=distutils.sysconfig.get_python_lib()
4747
DEFAULT_PIMPDATABASE_FMT="http://www.python.org/packman/version-%s/%s-%s-%s-%s-%s.plist"
4848

49+
def getDefaultDatabase(experimental=False):
50+
if experimental:
51+
status = "exp"
52+
else:
53+
status = "prod"
54+
55+
major, minor, micro, state, extra = sys.version_info
56+
pyvers = '%d.%d' % (major, minor)
57+
if state != 'final':
58+
pyvers = pyvers + '%s%d' % (state, extra)
59+
60+
longplatform = distutils.util.get_platform()
61+
osname, release, machine = longplatform.split('-')
62+
# For some platforms we may want to differentiate between
63+
# installation types
64+
if osname == 'darwin':
65+
if sys.prefix.startswith('/System/Library/Frameworks/Python.framework'):
66+
osname = 'darwin_apple'
67+
elif sys.prefix.startswith('/Library/Frameworks/Python.framework'):
68+
osname = 'darwin_macpython'
69+
# Otherwise we don't know...
70+
# Now we try various URLs by playing with the release string.
71+
# We remove numbers off the end until we find a match.
72+
rel = release
73+
while True:
74+
url = DEFAULT_PIMPDATABASE_FMT % (PIMP_VERSION, status, pyvers, osname, rel, machine)
75+
try:
76+
urllib2.urlopen(url)
77+
except urllib2.HTTPError, arg:
78+
pass
79+
else:
80+
break
81+
if not rel:
82+
# We're out of version numbers to try. Use the
83+
# full release number, this will give a reasonable
84+
# error message later
85+
url = DEFAULT_PIMPDATABASE_FMT % (PIMP_VERSION, status, pyvers, osname, release, machine)
86+
break
87+
idx = rel.rfind('.')
88+
if idx < 0:
89+
rel = ''
90+
else:
91+
rel = rel[:idx]
92+
return url
93+
4994
def _cmd(output, dir, *cmditems):
5095
"""Internal routine to run a shell command in a given directory."""
5196

@@ -163,7 +208,7 @@ def __init__(self,
163208
if not buildDir:
164209
buildDir = DEFAULT_BUILDDIR
165210
if not pimpDatabase:
166-
pimpDatabase = self.getDefaultDatabase()
211+
pimpDatabase = getDefaultDatabase()
167212
self.setInstallDir(installDir)
168213
self.flavorOrder = flavorOrder
169214
self.downloadDir = downloadDir
@@ -185,53 +230,6 @@ def setInstallDir(self, installDir=None):
185230

186231
def isUserInstall(self):
187232
return self.installDir != DEFAULT_INSTALLDIR
188-
189-
def getDefaultDatabase(self, experimental=False):
190-
if experimental:
191-
status = "exp"
192-
else:
193-
status = "prod"
194-
195-
major, minor, micro, state, extra = sys.version_info
196-
pyvers = '%d.%d' % (major, minor)
197-
if state != 'final':
198-
pyvers = pyvers + '%s%d' % (state, extra)
199-
200-
longplatform = distutils.util.get_platform()
201-
osname, release, machine = longplatform.split('-')
202-
# For some platforms we may want to differentiate between
203-
# installation types
204-
if osname == 'darwin':
205-
if sys.prefix.startswith('/System/Library/Frameworks/Python.framework'):
206-
osname = 'darwin_apple'
207-
elif sys.prefix.startswith('/Library/Frameworks/Python.framework'):
208-
osname = 'darwin_macpython'
209-
# Otherwise we don't know...
210-
# Now we try various URLs by playing with the release string.
211-
# We remove numbers off the end until we find a match.
212-
rel = release
213-
while True:
214-
url = DEFAULT_PIMPDATABASE_FMT % (PIMP_VERSION, status, pyvers, osname, rel, machine)
215-
try:
216-
urllib2.urlopen(url)
217-
except urllib2.HTTPError, arg:
218-
print 'getDefaultDatabase: cannot open', url
219-
print 'error', arg
220-
pass
221-
else:
222-
break
223-
if not rel:
224-
# We're out of version numbers to try. Use the
225-
# full release number, this will give a reasonable
226-
# error message later
227-
url = DEFAULT_PIMPDATABASE_FMT % (PIMP_VERSION, status, pyvers, osname, release, machine)
228-
break
229-
idx = rel.rfind('.')
230-
if idx < 0:
231-
rel = ''
232-
else:
233-
rel = rel[:idx]
234-
return url
235233

236234
def check(self):
237235
"""Check that the preferences make sense: directories exist and are

0 commit comments

Comments
 (0)