ProjectPyramid/Project.py

changeset 144
5c3684ee818e
parent 143
4ef44e854b39
child 147
eb28b4b6f7f5
diff -r 4ef44e854b39 -r 5c3684ee818e ProjectPyramid/Project.py
--- a/ProjectPyramid/Project.py	Wed Dec 30 11:02:09 2020 +0100
+++ b/ProjectPyramid/Project.py	Mon Apr 26 17:41:12 2021 +0200
@@ -10,6 +10,7 @@
 import os
 import re
 import configparser
+import contextlib
 
 from PyQt5.QtCore import QObject, QFileInfo, QTimer, QUrl
 from PyQt5.QtGui import QDesktopServices
@@ -51,14 +52,16 @@
         if args is None:
             args = []
         
-        if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
-                         'mate-terminal')):
-            if '-e' in args:
-                index = args.index('-e') + 1
-                cargs = ' '.join(args[index:])
-                args[index:] = [cargs]
+        if (
+            cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
+                          'mate-terminal')) and
+            '-e' in args
+        ):
+            index = args.index('-e') + 1
+            cargs = ' '.join(args[index:])
+            args[index:] = [cargs]
         
-        super(QProcess, self).start(cmd, args, mode)
+        super().start(cmd, args, mode)
     
     @staticmethod
     def startDetached(cmd, args=None, path=''):
@@ -74,12 +77,14 @@
         if args is None:
             args = []
         
-        if cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
-                         'mate-terminal')):
-            if '-e' in args:
-                index = args.index('-e') + 1
-                cargs = ' '.join(args[index:])
-                args[index:] = [cargs]
+        if (
+            cmd.endswith(('gnome-terminal', 'konsole', 'xfce4-terminal',
+                          'mate-terminal')) and
+            '-e' in args
+        ):
+            index = args.index('-e') + 1
+            cargs = ' '.join(args[index:])
+            args[index:] = [cargs]
         
         return QProcessPyQt.startDetached(cmd, args, path)
 
@@ -99,7 +104,7 @@
         @param parent parent
         @type QObject
         """
-        super(Project, self).__init__(parent)
+        super().__init__(parent)
         
         self.__plugin = plugin
         self.__iconSuffix = iconSuffix
@@ -587,9 +592,8 @@
                 return []
             
         cur_path = os.path.join(os.curdir, file)
-        if os.path.exists(cur_path):
-            if os.access(cur_path, os.X_OK):
-                paths.append(cur_path)
+        if os.path.exists(cur_path) and os.access(cur_path, os.X_OK):
+            paths.append(cur_path)
 
         path = os.getenv('PATH')
         
@@ -818,7 +822,7 @@
                     lines = f.read().splitlines()
                 for line in lines:
                     if line.startswith("__requires__"):
-                        ## sample: __requires__ = 'pyramid==1.4'
+                        #- sample: __requires__ = 'pyramid==1.4'
                         vers = line.strip().split()[-1][1:-1].split("==")[1]
                         self.__pyramidVersion = vers
             except OSError:
@@ -999,19 +1003,16 @@
         else:
             self.__currentProject = project
         
-        if self.__currentProject is None:
-            curProject = self.tr("None")
-        else:
-            curProject = self.__currentProject
+        curProject = (
+            self.tr("None")
+            if self.__currentProject is None else
+            self.__currentProject
+        )
         self.selectProjectAct.setText(
             self.tr('&Current Pyramid Project ({0})').format(curProject))
         
         if self.__currentProject is None:
-            try:
-                self.__e5project.setTranslationPattern("")
-            except AttributeError:
-                # backward compatibility
-                self.__e5project.pdata["TRANSLATIONPATTERN"] = []
+            self.__e5project.setTranslationPattern("")
         else:
             lowerProject = self.__project().lower()
             config = configparser.ConfigParser()
@@ -1024,17 +1025,10 @@
                 domain = config.get("init_catalog", "domain")
             except (configparser.NoOptionError, configparser.NoSectionError):
                 domain = lowerProject
-            try:
-                self.__e5project.setTranslationPattern(
-                    os.path.join(project, outputDir, "%language%",
-                                 "LC_MESSAGES", "{0}.po".format(domain))
-                )
-            except AttributeError:
-                # backward compatibility
-                self.__e5project.pdata["TRANSLATIONPATTERN"] = [
-                    os.path.join(project, outputDir, "%language%",
-                                 "LC_MESSAGES", "{0}.po".format(domain))
-                ]
+            self.__e5project.setTranslationPattern(
+                os.path.join(project, outputDir, "%language%",
+                             "LC_MESSAGES", "{0}.po".format(domain))
+            )
         
         if self.__currentProject is None:
             self.initializeDbAct.setEnabled(False)
@@ -1500,11 +1494,9 @@
                 self.tr('No "output_file" option found in setup.cfg.'))
             return
         
-        try:
+        with contextlib.suppress(OSError):
             path = os.path.join(projectPath, os.path.dirname(potFile))
             os.makedirs(path)
-        except OSError:
-            pass
         
         cmd = self.getPythonCommand()
         args = []

eric ide

mercurial