eric6/Utilities/__init__.py

changeset 7259
7c017076c12e
parent 7229
53054eb5b15a
child 7329
72f3c9fdefeb
equal deleted inserted replaced
7258:aff39db4dacc 7259:7c017076c12e
40 import warnings 40 import warnings
41 warnings.showwarning = __showwarning 41 warnings.showwarning = __showwarning
42 42
43 from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32 43 from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF32
44 44
45 from PyQt5.QtCore import QRegExp, QDir, QProcess, Qt, QByteArray, \ 45 from PyQt5.QtCore import (
46 qVersion, PYQT_VERSION_STR, QCoreApplication, QCryptographicHash 46 QRegExp, QDir, QProcess, Qt, QByteArray, qVersion, PYQT_VERSION_STR,
47 QCoreApplication, QCryptographicHash
48 )
47 from PyQt5.Qsci import QSCINTILLA_VERSION_STR, QsciScintilla 49 from PyQt5.Qsci import QSCINTILLA_VERSION_STR, QsciScintilla
48 50
49 # import these methods into the Utilities namespace 51 # import these methods into the Utilities namespace
50 from Globals import ( # __IGNORE_WARNING__ 52 from Globals import ( # __IGNORE_WARNING__
51 isWindowsPlatform, isLinuxPlatform, isMacPlatform, desktopName, 53 isWindowsPlatform, isLinuxPlatform, isMacPlatform, desktopName,
226 if Preferences.getEditor("AdvancedEncodingDetection"): 228 if Preferences.getEditor("AdvancedEncodingDetection"):
227 # Try the universal character encoding detector 229 # Try the universal character encoding detector
228 try: 230 try:
229 import ThirdParty.CharDet.chardet 231 import ThirdParty.CharDet.chardet
230 guess = ThirdParty.CharDet.chardet.detect(text) 232 guess = ThirdParty.CharDet.chardet.detect(text)
231 if guess and guess['confidence'] > 0.95 and \ 233 if (
232 guess['encoding'] is not None: 234 guess and
235 guess['confidence'] > 0.95 and
236 guess['encoding'] is not None
237 ):
233 codec = guess['encoding'].lower() 238 codec = guess['encoding'].lower()
234 return str(text, codec), '{0}-guessed'.format(codec) 239 return str(text, codec), '{0}-guessed'.format(codec)
235 except (UnicodeError, LookupError): 240 except (UnicodeError, LookupError):
236 pass 241 pass
237 except ImportError: 242 except ImportError:
348 353
349 if encoding is None: 354 if encoding is None:
350 # Try the original encoding 355 # Try the original encoding
351 if origEncoding and origEncoding.endswith( 356 if origEncoding and origEncoding.endswith(
352 ('-selected', '-default', '-guessed', '-ignore')): 357 ('-selected', '-default', '-guessed', '-ignore')):
353 coding = origEncoding\ 358 coding = (
354 .replace("-selected", "")\ 359 origEncoding
355 .replace("-default", "")\ 360 .replace("-selected", "")
356 .replace("-guessed", "")\ 361 .replace("-default", "")
362 .replace("-guessed", "")
357 .replace("-ignore", "") 363 .replace("-ignore", "")
364 )
358 try: 365 try:
359 etext, encoding = text.encode(coding), coding 366 etext, encoding = text.encode(coding), coding
360 except (UnicodeError, LookupError): 367 except (UnicodeError, LookupError):
361 pass 368 pass
362 369
1057 @return flag indicating a Windows drive 1064 @return flag indicating a Windows drive
1058 @rtype bool 1065 @rtype bool
1059 """ 1066 """
1060 isDrive = False 1067 isDrive = False
1061 drive, directory = os.path.splitdrive(path) 1068 drive, directory = os.path.splitdrive(path)
1062 if drive and len(drive) == 2 and drive.endswith(":") and \ 1069 if (
1063 directory in ["", "\\", "/"]: 1070 drive and
1071 len(drive) == 2 and
1072 drive.endswith(":") and
1073 directory in ["", "\\", "/"]
1074 ):
1064 isDrive = True 1075 isDrive = True
1065 1076
1066 return isDrive 1077 return isDrive
1067 1078
1068 1079
1076 same path on disk. 1087 same path on disk.
1077 """ 1088 """
1078 if f1 is None or f2 is None: 1089 if f1 is None or f2 is None:
1079 return False 1090 return False
1080 1091
1081 if normcaseabspath(os.path.realpath(f1)) == \ 1092 if (
1082 normcaseabspath(os.path.realpath(f2)): 1093 normcaseabspath(os.path.realpath(f1)) ==
1094 normcaseabspath(os.path.realpath(f2))
1095 ):
1083 return True 1096 return True
1084 1097
1085 return False 1098 return False
1086 1099
1087 1100
1208 '.ropeproject', 1221 '.ropeproject',
1209 '.eric6project']: 1222 '.eric6project']:
1210 continue 1223 continue
1211 1224
1212 fentry = os.path.join(path, entry) 1225 fentry = os.path.join(path, entry)
1213 if pattern and \ 1226 if (
1214 not os.path.isdir(fentry) and \ 1227 pattern and
1215 not fnmatch.fnmatch(entry, pattern): 1228 not os.path.isdir(fentry) and
1229 not fnmatch.fnmatch(entry, pattern)
1230 ):
1216 # entry doesn't fit the given pattern 1231 # entry doesn't fit the given pattern
1217 continue 1232 continue
1218 1233
1219 if os.path.isdir(fentry): 1234 if os.path.isdir(fentry):
1220 if os.path.islink(fentry) and not followsymlinks: 1235 if os.path.islink(fentry) and not followsymlinks:
1243 except EnvironmentError: 1258 except EnvironmentError:
1244 return [] 1259 return []
1245 1260
1246 dirs = [] 1261 dirs = []
1247 for name in names: 1262 for name in names:
1248 if os.path.isdir(os.path.join(path, name)) and \ 1263 if (
1249 not os.path.islink(os.path.join(path, name)): 1264 os.path.isdir(os.path.join(path, name)) and
1265 not os.path.islink(os.path.join(path, name))
1266 ):
1250 exclude = 0 1267 exclude = 0
1251 for e in excludeDirs: 1268 for e in excludeDirs:
1252 if name.split(os.sep, 1)[0] == e: 1269 if name.split(os.sep, 1)[0] == e:
1253 exclude = 1 1270 exclude = 1
1254 break 1271 break
1821 interpreterIndex = not interpreterIndex 1838 interpreterIndex = not interpreterIndex
1822 if interpreterIndex: 1839 if interpreterIndex:
1823 venvName = Preferences.getDebugger("Python3VirtualEnv") 1840 venvName = Preferences.getDebugger("Python3VirtualEnv")
1824 else: 1841 else:
1825 venvName = Preferences.getDebugger("Python2VirtualEnv") 1842 venvName = Preferences.getDebugger("Python2VirtualEnv")
1826 interpreter = e5App().getObject("VirtualEnvManager")\ 1843 interpreter = e5App().getObject(
1827 .getVirtualenvInterpreter(venvName) 1844 "VirtualEnvManager").getVirtualenvInterpreter(venvName)
1828 prefix = os.path.dirname(interpreter) 1845 prefix = os.path.dirname(interpreter)
1829 if toolname in ["pyside-uic", "pyside2-uic"]: 1846 if toolname in ["pyside-uic", "pyside2-uic"]:
1830 return os.path.join(prefix, "Scripts", toolname + '.exe') 1847 return os.path.join(prefix, "Scripts", toolname + '.exe')
1831 else: 1848 else:
1832 return os.path.join( 1849 return os.path.join(
1858 assert variant in ("1", "2") 1875 assert variant in ("1", "2")
1859 1876
1860 pysideInformation = [] 1877 pysideInformation = []
1861 for venvNameKey in ["Python2VirtualEnv", "Python3VirtualEnv"]: 1878 for venvNameKey in ["Python2VirtualEnv", "Python3VirtualEnv"]:
1862 venvName = Preferences.getDebugger(venvNameKey) 1879 venvName = Preferences.getDebugger(venvNameKey)
1863 interpreter = e5App().getObject("VirtualEnvManager")\ 1880 interpreter = e5App().getObject(
1864 .getVirtualenvInterpreter(venvName) 1881 "VirtualEnvManager").getVirtualenvInterpreter(venvName)
1865 if interpreter == "" or not isinpath(interpreter): 1882 if interpreter == "" or not isinpath(interpreter):
1866 hasPyside = False 1883 hasPyside = False
1867 else: 1884 else:
1868 hasPyside = False 1885 hasPyside = False
1869 checker = os.path.join(getConfig('ericDir'), 1886 checker = os.path.join(getConfig('ericDir'),

eric ide

mercurial