ProjectPyramid/Project.py

changeset 144
5c3684ee818e
parent 143
4ef44e854b39
child 147
eb28b4b6f7f5
equal deleted inserted replaced
143:4ef44e854b39 144:5c3684ee818e
8 """ 8 """
9 9
10 import os 10 import os
11 import re 11 import re
12 import configparser 12 import configparser
13 import contextlib
13 14
14 from PyQt5.QtCore import QObject, QFileInfo, QTimer, QUrl 15 from PyQt5.QtCore import QObject, QFileInfo, QTimer, QUrl
15 from PyQt5.QtGui import QDesktopServices 16 from PyQt5.QtGui import QDesktopServices
16 from PyQt5.QtWidgets import QMenu, QDialog, QInputDialog, QLineEdit 17 from PyQt5.QtWidgets import QMenu, QDialog, QInputDialog, QLineEdit
17 from PyQt5.QtCore import QProcess as QProcessPyQt 18 from PyQt5.QtCore import QProcess as QProcessPyQt
49 @keyparam mode access mode (QIODevice.OpenMode) 50 @keyparam mode access mode (QIODevice.OpenMode)
50 """ 51 """
51 if args is None: 52 if args is None:
52 args = [] 53 args = []
53 54
54 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', 55 if (
55 'mate-terminal')): 56 cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
56 if '-e' in args: 57 'mate-terminal')) and
57 index = args.index('-e') + 1 58 '-e' in args
58 cargs = ' '.join(args[index:]) 59 ):
59 args[index:] = [cargs] 60 index = args.index('-e') + 1
60 61 cargs = ' '.join(args[index:])
61 super(QProcess, self).start(cmd, args, mode) 62 args[index:] = [cargs]
63
64 super().start(cmd, args, mode)
62 65
63 @staticmethod 66 @staticmethod
64 def startDetached(cmd, args=None, path=''): 67 def startDetached(cmd, args=None, path=''):
65 """ 68 """
66 Public static method to start the given program (cmd) in a new process, 69 Public static method to start the given program (cmd) in a new process,
72 @return tuple of successful start and process id (boolean, integer) 75 @return tuple of successful start and process id (boolean, integer)
73 """ 76 """
74 if args is None: 77 if args is None:
75 args = [] 78 args = []
76 79
77 if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal', 80 if (
78 'mate-terminal')): 81 cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
79 if '-e' in args: 82 'mate-terminal')) and
80 index = args.index('-e') + 1 83 '-e' in args
81 cargs = ' '.join(args[index:]) 84 ):
82 args[index:] = [cargs] 85 index = args.index('-e') + 1
86 cargs = ' '.join(args[index:])
87 args[index:] = [cargs]
83 88
84 return QProcessPyQt.startDetached(cmd, args, path) 89 return QProcessPyQt.startDetached(cmd, args, path)
85 90
86 91
87 class Project(QObject): 92 class Project(QObject):
97 @param iconSuffix suffix for the icons 102 @param iconSuffix suffix for the icons
98 @type str 103 @type str
99 @param parent parent 104 @param parent parent
100 @type QObject 105 @type QObject
101 """ 106 """
102 super(Project, self).__init__(parent) 107 super().__init__(parent)
103 108
104 self.__plugin = plugin 109 self.__plugin = plugin
105 self.__iconSuffix = iconSuffix 110 self.__iconSuffix = iconSuffix
106 self.__ui = parent 111 self.__ui = parent
107 self.__e5project = e5App().getObject("Project") 112 self.__e5project = e5App().getObject("Project")
585 return [file] 590 return [file]
586 else: 591 else:
587 return [] 592 return []
588 593
589 cur_path = os.path.join(os.curdir, file) 594 cur_path = os.path.join(os.curdir, file)
590 if os.path.exists(cur_path): 595 if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
591 if os.access(cur_path, os.X_OK): 596 paths.append(cur_path)
592 paths.append(cur_path)
593 597
594 path = os.getenv('PATH') 598 path = os.getenv('PATH')
595 599
596 # environment variable not defined 600 # environment variable not defined
597 if path is not None: 601 if path is not None:
816 try: 820 try:
817 with open(cmd, 'r', encoding="utf-8") as f: 821 with open(cmd, 'r', encoding="utf-8") as f:
818 lines = f.read().splitlines() 822 lines = f.read().splitlines()
819 for line in lines: 823 for line in lines:
820 if line.startswith("__requires__"): 824 if line.startswith("__requires__"):
821 ## sample: __requires__ = 'pyramid==1.4' 825 #- sample: __requires__ = 'pyramid==1.4'
822 vers = line.strip().split()[-1][1:-1].split("==")[1] 826 vers = line.strip().split()[-1][1:-1].split("==")[1]
823 self.__pyramidVersion = vers 827 self.__pyramidVersion = vers
824 except OSError: 828 except OSError:
825 self.__pyramidVersion = "" 829 self.__pyramidVersion = ""
826 830
997 if project is not None and len(project) == 0: 1001 if project is not None and len(project) == 0:
998 self.__currentProject = None 1002 self.__currentProject = None
999 else: 1003 else:
1000 self.__currentProject = project 1004 self.__currentProject = project
1001 1005
1002 if self.__currentProject is None: 1006 curProject = (
1003 curProject = self.tr("None") 1007 self.tr("None")
1004 else: 1008 if self.__currentProject is None else
1005 curProject = self.__currentProject 1009 self.__currentProject
1010 )
1006 self.selectProjectAct.setText( 1011 self.selectProjectAct.setText(
1007 self.tr('&Current Pyramid Project ({0})').format(curProject)) 1012 self.tr('&Current Pyramid Project ({0})').format(curProject))
1008 1013
1009 if self.__currentProject is None: 1014 if self.__currentProject is None:
1010 try: 1015 self.__e5project.setTranslationPattern("")
1011 self.__e5project.setTranslationPattern("")
1012 except AttributeError:
1013 # backward compatibility
1014 self.__e5project.pdata["TRANSLATIONPATTERN"] = []
1015 else: 1016 else:
1016 lowerProject = self.__project().lower() 1017 lowerProject = self.__project().lower()
1017 config = configparser.ConfigParser() 1018 config = configparser.ConfigParser()
1018 config.read(os.path.join(self.__projectPath(), "setup.cfg")) 1019 config.read(os.path.join(self.__projectPath(), "setup.cfg"))
1019 try: 1020 try:
1022 outputDir = '{0}/locale'.format(lowerProject) 1023 outputDir = '{0}/locale'.format(lowerProject)
1023 try: 1024 try:
1024 domain = config.get("init_catalog", "domain") 1025 domain = config.get("init_catalog", "domain")
1025 except (configparser.NoOptionError, configparser.NoSectionError): 1026 except (configparser.NoOptionError, configparser.NoSectionError):
1026 domain = lowerProject 1027 domain = lowerProject
1027 try: 1028 self.__e5project.setTranslationPattern(
1028 self.__e5project.setTranslationPattern( 1029 os.path.join(project, outputDir, "%language%",
1029 os.path.join(project, outputDir, "%language%", 1030 "LC_MESSAGES", "{0}.po".format(domain))
1030 "LC_MESSAGES", "{0}.po".format(domain)) 1031 )
1031 )
1032 except AttributeError:
1033 # backward compatibility
1034 self.__e5project.pdata["TRANSLATIONPATTERN"] = [
1035 os.path.join(project, outputDir, "%language%",
1036 "LC_MESSAGES", "{0}.po".format(domain))
1037 ]
1038 1032
1039 if self.__currentProject is None: 1033 if self.__currentProject is None:
1040 self.initializeDbAct.setEnabled(False) 1034 self.initializeDbAct.setEnabled(False)
1041 else: 1035 else:
1042 initCmd = self.__getInitDbCommand() 1036 initCmd = self.__getInitDbCommand()
1498 self.__ui, 1492 self.__ui,
1499 title, 1493 title,
1500 self.tr('No "output_file" option found in setup.cfg.')) 1494 self.tr('No "output_file" option found in setup.cfg.'))
1501 return 1495 return
1502 1496
1503 try: 1497 with contextlib.suppress(OSError):
1504 path = os.path.join(projectPath, os.path.dirname(potFile)) 1498 path = os.path.join(projectPath, os.path.dirname(potFile))
1505 os.makedirs(path) 1499 os.makedirs(path)
1506 except OSError:
1507 pass
1508 1500
1509 cmd = self.getPythonCommand() 1501 cmd = self.getPythonCommand()
1510 args = [] 1502 args = []
1511 args.append("setup.py") 1503 args.append("setup.py")
1512 args.append("extract_messages") 1504 args.append("extract_messages")

eric ide

mercurial