PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/util/black/lib/python/black/configure/std.py

https://gitlab.com/Smileyt/KomodoEdit
Python | 490 lines | 363 code | 66 blank | 61 comment | 99 complexity | 3227a04981374b42e775796a53c4eb80 MD5 | raw file
  1. # ***** BEGIN LICENSE BLOCK *****
  2. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3. #
  4. # The contents of this file are subject to the Mozilla Public License
  5. # Version 1.1 (the "License"); you may not use this file except in
  6. # compliance with the License. You may obtain a copy of the License at
  7. # http://www.mozilla.org/MPL/
  8. #
  9. # Software distributed under the License is distributed on an "AS IS"
  10. # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  11. # License for the specific language governing rights and limitations
  12. # under the License.
  13. #
  14. # The Original Code is Komodo code.
  15. #
  16. # The Initial Developer of the Original Code is ActiveState Software Inc.
  17. # Portions created by ActiveState Software Inc are Copyright (C) 2000-2007
  18. # ActiveState Software Inc. All Rights Reserved.
  19. #
  20. # Contributor(s):
  21. # ActiveState Software Inc
  22. #
  23. # Alternatively, the contents of this file may be used under the terms of
  24. # either the GNU General Public License Version 2 or later (the "GPL"), or
  25. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  26. # in which case the provisions of the GPL or the LGPL are applicable instead
  27. # of those above. If you wish to allow use of your version of this file only
  28. # under the terms of either the GPL or the LGPL, and not to allow others to
  29. # use your version of this file under the terms of the MPL, indicate your
  30. # decision by deleting the provisions above and replace them with the notice
  31. # and other provisions required by the GPL or the LGPL. If you do not delete
  32. # the provisions above, a recipient may use your version of this file under
  33. # the terms of any one of the MPL, the GPL or the LGPL.
  34. #
  35. # ***** END LICENSE BLOCK *****
  36. #
  37. # A set of standard (and hopefully generally useful) Black configuration
  38. # items.
  39. #
  40. import os, sys, re
  41. if sys.platform.startswith("win"):
  42. import _winreg
  43. import tmShUtil
  44. import black.configure
  45. from black.configure import Datum, ConfigureError, RunEnvScript, BooleanDatum
  46. #---- Black specific items
  47. #---- general system configuration items
  48. class SystemDirs(Datum):
  49. def __init__(self):
  50. Datum.__init__(self, "systemDirs", desc="the system directories")
  51. def _Determine_Do(self):
  52. if sys.platform.startswith("win"):
  53. self.applicable = 1
  54. try:
  55. sysRoot = os.environ["SystemRoot"]
  56. except KeyError:
  57. # Win98 (how about Win95?)
  58. sysRoot = os.environ["windir"]
  59. self.value = []
  60. self.value.append(sysRoot)
  61. self.value.append(os.path.join(sysRoot, "system32"))
  62. elif sys.platform.startswith("sunos"):
  63. self.applicable = 1
  64. self.value = ["/usr/local/bin", "/usr/bin/", "/usr/ccs/bin",
  65. "/usr/ucb", "/bin"]
  66. else:
  67. self.applicable = 1
  68. self.value = ["/usr/local/bin", "/usr/bin", "/bin"]
  69. self.determined = 1
  70. class Path(Datum):
  71. def __init__(self):
  72. Datum.__init__(self, "path", desc="the configured PATH setting")
  73. def _Determine_Do(self):
  74. # If there is a PATH configuration item, then return its value.
  75. # Otherwise return the value of the PATH environment variable.
  76. if black.configure.items.has_key("PATH"):
  77. pathItem = black.configure.items["PATH"]
  78. self.applicable = pathItem.Determine()
  79. if self.applicable:
  80. self.value = pathItem.Get()
  81. else:
  82. self.applicable = 1
  83. self.value = os.environ["PATH"].split(os.pathsep)
  84. self.determined = 1
  85. #---- some MSVC configuration items
  86. class MsvcInstallDir(Datum):
  87. def __init__(self, compilerVersion="vc6"):
  88. Datum.__init__(self, "msvcInstallDir",
  89. desc="the installation directory of Microsoft Visual %s" % (compilerVersion),
  90. serializeAs=[])
  91. self._compilerVersion = compilerVersion.lower()
  92. def _Determine_Sufficient(self):
  93. if self.value is None:
  94. raise ConfigureError("Could not determine %s. Do you have "\
  95. "Visual Studio installed? If so, then there is a bug in the "\
  96. "configure code or it has to be extended "\
  97. "for the weird way you setup your machine.\n" % self.desc)
  98. def _Determine_Do(self):
  99. if sys.platform.startswith("win"):
  100. self.applicable = 1
  101. # look in the registry:
  102. # HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/DevStudio/6.0/Products\
  103. # /Microsoft Visual C++/ProductDir
  104. try:
  105. if self._compilerVersion.startswith("vc6"):
  106. key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
  107. "SOFTWARE\\Microsoft\\DevStudio\\6.0\\Products"\
  108. "\\Microsoft Visual C++")
  109. elif self._compilerVersion.startswith("vc7") or \
  110. self._compilerVersion.startswith("vc8"):
  111. key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
  112. "SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VC7")
  113. else:
  114. # Unknown compiler version
  115. raise WindowsError("Unknown windows compiler version")
  116. except WindowsError:
  117. self.value = None
  118. else:
  119. numSubkeys, numValues, lastModified = _winreg.QueryInfoKey(key)
  120. for i in range(numValues):
  121. valueName, valueData, dataType = _winreg.EnumValue(key, i)
  122. if self._compilerVersion.startswith("vc7") and \
  123. (valueName == '7.1'):
  124. self.value = str(valueData) # convert from Unicode
  125. break
  126. elif self._compilerVersion.startswith("vc8") and \
  127. (valueName == '8.0'):
  128. self.value = str(valueData) # convert from Unicode
  129. break
  130. elif self._compilerVersion.startswith("vc6") and \
  131. (valueName == 'ProductDir'):
  132. self.value = str(valueData) # convert from Unicode
  133. break
  134. else:
  135. # otherwise just try the default hardcoded path
  136. if self._compilerVersion.startswith("vc6"):
  137. installDir =\
  138. "C:\\Program Files\\Microsoft Visual Studio\\VC98";
  139. elif self._compilerVersion.startswith("vc7"):
  140. installDir =\
  141. "C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Vc7";
  142. elif self._compilerVersion.startswith("vc8"):
  143. installDir =\
  144. "C:\\Program Files\\Microsoft Visual Studio 8\\VC";
  145. if os.path.isdir(installDir):
  146. self.value = installDir
  147. else:
  148. self.value = None
  149. else:
  150. self.applicable = 0
  151. self.determined = 1
  152. class SetupMsvc(RunEnvScript):
  153. def __init__(self):
  154. RunEnvScript.__init__(self, "setupMsvc",
  155. desc="how to setup environment for MSVC")
  156. def _Determine_Sufficient(self):
  157. if self.value is None:
  158. raise ConfigureError("Could not determine %s.\n" % self.desc)
  159. def _Determine_Do(self):
  160. if sys.platform.startswith("win"):
  161. #XXX should this be conditional on MSDevDir???
  162. self.applicable = 1
  163. msvcInstallDir = black.configure.items['msvcInstallDir'].Get()
  164. vcvars32Bat = os.path.join(msvcInstallDir, 'bin', 'vcvars32.bat')
  165. if os.path.isfile(vcvars32Bat):
  166. self.value = vcvars32Bat
  167. else:
  168. self.value = None
  169. else:
  170. self.applicable = 0
  171. self.value = None
  172. self.determined = 1
  173. class MsvcrtDebugDllsInstalled(BooleanDatum):
  174. def __init__(self):
  175. Datum.__init__(self, "msvcrtDebugDllsInstalled",
  176. desc="the Microsoft Runtime debugging DLLs installed")
  177. def _Determine_Sufficient(self):
  178. if not self.value:
  179. raise ConfigureError("The Microsoft Runtime debugging DLLs are "\
  180. "not installed on this machine. You have to install them.\n")
  181. def _Determine_Do(self):
  182. # optionally use the "buildType" configuration item, if defined,
  183. # to determine if this item is applicable
  184. if sys.platform.startswith("win"):
  185. if black.configure.items.has_key("buildType") and\
  186. black.configure.items["buildType"].Get() != "debug":
  187. self.applicable = 0
  188. else:
  189. self.applicable = 1
  190. if not black.configure.items.has_key("systemDirs"):
  191. black.configure.items["systemDirs"] =\
  192. black.configure.std.SystemDirs()
  193. systemDirs = black.configure.items["systemDirs"].Get()
  194. msvcrtdDll = tmShUtil.Which("msvcrtd.dll", systemDirs)
  195. msvcirtdDll = tmShUtil.Which("msvcirtd.dll", systemDirs)
  196. if not (msvcrtdDll and msvcirtdDll):
  197. self.value = 0
  198. else:
  199. self.value = 1
  200. else:
  201. self.applicable = 0
  202. self.determined = 1
  203. #---- Python, Perl, PHP configuration items
  204. class PythonExeName(Datum):
  205. def __init__(self):
  206. Datum.__init__(self, "pythonExeName",
  207. desc="the name of the Python executable")
  208. def _Determine_Do(self):
  209. self.applicable = 1
  210. if sys.platform.startswith("win"):
  211. if black.configure.items.has_key("buildType") and\
  212. black.configure.items["buildType"].Get() == "debug":
  213. self.value = "python_d.exe"
  214. else:
  215. self.value = "python.exe"
  216. else:
  217. self.value = "python"
  218. self.determined = 1
  219. class PythonVersion(Datum):
  220. def __init__(self):
  221. Datum.__init__(self, "pythonVersion", desc="the python version")
  222. def _Determine_Do(self):
  223. self.applicable = 1
  224. if not black.configure.items.has_key("pythonExeName"):
  225. black.configure.items["pythonExeName"] = PythonExeName()
  226. pythonExeName = black.configure.items["pythonExeName"].Get()
  227. o = os.popen('%s -c "import sys; sys.stdout.write(\'.\'.join(map(str, sys.version_info[:3])))"' % pythonExeName)
  228. self.value = o.read()
  229. self.determined = 1
  230. class PerlBinDir(Datum):
  231. def __init__(self):
  232. Datum.__init__(self, "perlBinDir", desc="the Perl bin directory")
  233. def _Determine_Sufficient(self):
  234. if self.value is None:
  235. raise ConfigureError("Could not determine %s (could not find "\
  236. "perl on your path). You have to install Perl and put it on "\
  237. "your path.\n" % self.desc)
  238. def _Determine_Do(self):
  239. self.applicable = 1
  240. perlExe = tmShUtil.WhichFollowSymLinks('perl')
  241. if perlExe:
  242. self.value = os.path.dirname(perlExe)
  243. else:
  244. self.value = None
  245. self.determined = 1
  246. class PhpBinDir(Datum):
  247. def __init__(self):
  248. Datum.__init__(self, "phpBinDir", desc="the PHP bin directory")
  249. def _Determine_Do(self):
  250. self.applicable = 1
  251. phpExe = tmShUtil.WhichFollowSymLinks('php')
  252. if phpExe:
  253. self.value = os.path.dirname(phpExe)
  254. else:
  255. self.value = None
  256. self.determined = 1
  257. class PythonBinDir(Datum):
  258. def __init__(self):
  259. Datum.__init__(self, "pythonBinDir", "the Python bin directory")
  260. def _Determine_Sufficient(self):
  261. if self.value is None:
  262. pythonExeName = black.configure.items["pythonExeName"].Get()
  263. raise ConfigureError("Could not determine %s (could not find %s "\
  264. "on your path). You have to install Python and put it on "\
  265. "your path.\n" % (self.desc, pythonExeName))
  266. def _Determine_Do(self):
  267. self.applicable = 1
  268. if not black.configure.items.has_key("pythonExeName"):
  269. black.configure.items["pythonExeName"] = PythonExeName()
  270. pythonExeName = black.configure.items["pythonExeName"].Get()
  271. pythonExe = tmShUtil.WhichFollowSymLinks(pythonExeName)
  272. if pythonExe:
  273. self.value = os.path.dirname(pythonExe)
  274. else:
  275. self.value = None
  276. self.determined = 1
  277. class PythonInstallDir(Datum):
  278. def __init__(self):
  279. Datum.__init__(self, "pythonInstallDir",
  280. desc="the Python installation directory")
  281. def _Determine_Sufficient(self):
  282. if self.value is None:
  283. raise ConfigureError("Could not determine %s.\n" % self.desc)
  284. def _Determine_Do(self):
  285. self.applicable = 1
  286. if not black.configure.items.has_key("pythonBinDir"):
  287. black.configure.items["pythonBinDir"] = PythonBinDir()
  288. pythonBinDir = black.configure.items["pythonBinDir"].Get()
  289. if pythonBinDir:
  290. from os.path import basename, dirname
  291. if sys.platform.startswith("win"):
  292. if basename(pythonBinDir).lower() == "pcbuild":
  293. self.value = dirname(pythonBinDir)
  294. else:
  295. self.value = pythonBinDir
  296. elif sys.platform == 'darwin':
  297. # foo/Python.framework/Versions/X.Y/bin -> foo
  298. self.value = dirname(dirname(dirname(dirname(pythonBinDir))))
  299. else:
  300. if basename(pythonBinDir) == "bin":
  301. self.value = dirname(pythonBinDir)
  302. else:
  303. self.value = pythonBinDir
  304. else:
  305. self.value = None
  306. self.determined = 1
  307. class PerlInstallDir(Datum):
  308. def __init__(self):
  309. Datum.__init__(self, "perlInstallDir",
  310. desc="Perl installation directory")
  311. def _Determine_Sufficient(self):
  312. if self.value is None:
  313. raise ConfigureError("Could not determine %s. You have to "\
  314. "install Perl and put it on your path.\n" % self.desc)
  315. def _Determine_Do(self):
  316. self.applicable = 1
  317. if not black.configure.items.has_key("perlBinDir"):
  318. black.configure.items["perlBinDir"] = PerlBinDir()
  319. perlBinDir = black.configure.items["perlBinDir"].Get()
  320. if perlBinDir:
  321. self.value = os.path.dirname(perlBinDir)
  322. else:
  323. self.value = None
  324. self.determined = 1
  325. class PerlVersion(Datum):
  326. def __init__(self, name=None, desc=None,
  327. # The id of the configuration item describing the perl
  328. # installation in which to check for these modules.
  329. perlBinDirItemName="perlBinDir"):
  330. self.perlBinDirItemName = perlBinDirItemName
  331. if name is None:
  332. name = "perlVersion"
  333. if desc is None:
  334. desc="the Perl version number"
  335. Datum.__init__(self, name, desc)
  336. def _Determine_Do(self):
  337. if not black.configure.items.has_key(self.perlBinDirItemName):
  338. black.configure.items[self.perlBinDirItemName] = PerlBinDir()
  339. self.applicable = black.configure.items[self.perlBinDirItemName].Determine()
  340. if self.applicable:
  341. perlBinDir = black.configure.items[self.perlBinDirItemName].Get()
  342. if perlBinDir:
  343. perlExe = os.path.join(perlBinDir, "perl")
  344. o = os.popen("%s -v" % perlExe)
  345. perlVersionDump = o.read()
  346. perlVersionMatch = re.compile("This is perl, v([0-9.]+)").\
  347. search(perlVersionDump)
  348. if perlVersionMatch:
  349. self.value = perlVersionMatch.group(1)
  350. else:
  351. self.value = None
  352. else:
  353. self.value = None
  354. self.determined = 1
  355. class ActivePerlBuild(Datum):
  356. def __init__(self, name=None, desc=None,
  357. # The id of the configuration item describing the perl
  358. # installation in which to check for these modules.
  359. perlBinDirItemName="perlBinDir"):
  360. self.perlBinDirItemName = perlBinDirItemName
  361. if name is None:
  362. name = "activePerlBuild"
  363. if desc is None:
  364. desc="the ActivePerl build number"
  365. Datum.__init__(self, name, desc)
  366. def _Determine_Do(self):
  367. if not black.configure.items.has_key(self.perlBinDirItemName):
  368. black.configure.items[self.perlBinDirItemName] = PerlBinDir()
  369. self.applicable = black.configure.items[self.perlBinDirItemName].Determine()
  370. if self.applicable:
  371. perlBinDir = black.configure.items[self.perlBinDirItemName].Get()
  372. if perlBinDir:
  373. perlExe = os.path.join(perlBinDir, "perl")
  374. o = os.popen("%s -v" % perlExe)
  375. perlVersionDump = o.read()
  376. buildMatch = re.compile(
  377. "Binary build (\d+) provided by ActiveState").\
  378. search(perlVersionDump)
  379. if buildMatch:
  380. self.value = buildMatch.group(1)
  381. else:
  382. self.value = None
  383. else:
  384. self.value = None
  385. self.determined = 1
  386. class PerlModulesInstalled(BooleanDatum):
  387. def __init__(self, name=None, desc=None,
  388. # The id of the configuration item describing the perl
  389. # installation in which to check for these modules.
  390. perlBinDirItemName="perlBinDir",
  391. modules=[], # the list of Perl module name to check for
  392. fatal=1): # true iff the modules *must* be installed
  393. self.perlBinDirItemName = perlBinDirItemName
  394. self.modules = modules
  395. self.fatal = fatal
  396. if name is None:
  397. name = "perlModulesInstalled"
  398. if desc is None:
  399. desc="the following Perl modules are installed: %s" % self.modules
  400. Datum.__init__(self, name, desc)
  401. def _Determine_Sufficient(self):
  402. if self.fatal and len(self.notInstalled) != 0:
  403. perlBinDir = black.configure.items[\
  404. self.perlBinDirItemName].Get()
  405. raise ConfigureError("The following required Perl modules "\
  406. "(%s) are not installed in your Perl installation (%s). You "\
  407. "have to install them.\n" % (self.notInstalled, perlBinDir))
  408. def _Determine_Do(self):
  409. self.applicable = 1
  410. if not black.configure.items.has_key(self.perlBinDirItemName):
  411. black.configure.items[self.perlBinDirItemName] = PerlBinDir()
  412. perlBinDir = black.configure.items[self.perlBinDirItemName].Get()
  413. perlExe = os.path.join(perlBinDir, "perl")
  414. self.value = []
  415. self.notInstalled = []
  416. for module in self.modules:
  417. o = os.popen('%s -m%s -e "print \'madeit\';"' % (perlExe, module))
  418. output = o.read()
  419. o.close()
  420. if output != "madeit":
  421. self.notInstalled.append(module)
  422. else:
  423. self.value.append(module)
  424. self.determined = 1