From 656c48d4a2b444ccceed18c0dc09664c8cf46213 Mon Sep 17 00:00:00 2001 From: Ilmari Lauhakangas Date: Sat, 27 Jul 2024 12:27:55 +0300 Subject: [PATCH] cui, dbaccess, desktop, external, filter, librelogo: fix issues found by Ruff linter Change-Id: I34df4c10520406a2b9d2d8f3487f877698a324f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171090 Tested-by: Jenkins Reviewed-by: Ilmari Lauhakangas Tested-by: Ilmari Lauhakangas --- cui/qa/uitest/dialogs/chardlg.py | 2 - dbaccess/qa/python/fdo84315.py | 4 +- .../test/deployment/active/active_python.py | 6 +- .../test/deployment/passive/passive_python.py | 4 +- external/nss/nsinstall.py | 2 +- filter/source/svg/gentoken.py | 4 +- filter/source/svg/js2hxx.py | 3 +- librelogo/source/LibreLogo/LibreLogo.py | 187 +++++++++--------- 8 files changed, 105 insertions(+), 107 deletions(-) diff --git a/cui/qa/uitest/dialogs/chardlg.py b/cui/qa/uitest/dialogs/chardlg.py index 686cb6472ac8..ee754b3c0f3a 100644 --- a/cui/qa/uitest/dialogs/chardlg.py +++ b/cui/qa/uitest/dialogs/chardlg.py @@ -149,8 +149,6 @@ class Test(UITestCase): def testSvxCharEffectsPageWriterAutomatic(self): # Start Writer. with self.ui_test.create_doc_in_start_center("writer"): - doc = self.xUITest.getTopFocusWindow() - # Use Format -> Character. with self.ui_test.execute_dialog_through_command(".uno:FontDialog") as xDialog: xTabs = xDialog.getChild("tabcontrol") diff --git a/dbaccess/qa/python/fdo84315.py b/dbaccess/qa/python/fdo84315.py index 680ba7495c3b..75954c0cd0b2 100644 --- a/dbaccess/qa/python/fdo84315.py +++ b/dbaccess/qa/python/fdo84315.py @@ -56,12 +56,12 @@ class Fdo84315(unittest.TestCase): xResultset = xStatement.executeQuery('SELECT "count" FROM "test_table"') expected_values = deque([42, 4711]) - xMeta = self.__test_Query('count', NUMERIC, xResultset) + self.__test_Query('count', NUMERIC, xResultset) self.__test_ResultSetInteger(xResultset, expected_values) xResultset = xStatement.executeQuery('SELECT "name" FROM "test_table"') expected_values = deque(['foo', 'bar']) - xMeta = self.__test_Query('name', VAR_CHAR, xResultset) + self.__test_Query('name', VAR_CHAR, xResultset) self.__test_ResultSetString(xResultset, expected_values) xResultset = xStatement.executeQuery('SELECT "id" FROM "test_table"') diff --git a/desktop/test/deployment/active/active_python.py b/desktop/test/deployment/active/active_python.py index 1d6a32749a80..c06db4bc9354 100644 --- a/desktop/test/deployment/active/active_python.py +++ b/desktop/test/deployment/active/active_python.py @@ -76,8 +76,8 @@ class Dispatch(unohelper.Base, XServiceInfo, XDispatch): "com.sun.star.frame.Desktop", self.context). \ getCurrentFrame().getComponentWindow(), \ INFOBOX, BUTTONS_OK, "active", "python") - box.execute(); - box.dispose(); + box.execute() + box.dispose() def addStatusListener(self, Control, URL): pass @@ -100,7 +100,7 @@ def writeRegistryInfo(smgr, regKey): for i in (Provider, Dispatch): key = regKey.createKey("/" + i.implementationName + "/UNO") for j in i.serviceNames: - key.createKey("/SERVICES/" + j); + key.createKey("/SERVICES/" + j) regKey.createKey( \ "/" + Dispatch.implementationName + "/UNO/SINGLETONS/" \ "com.sun.star.test.deployment.active_python_singleton"). \ diff --git a/desktop/test/deployment/passive/passive_python.py b/desktop/test/deployment/passive/passive_python.py index 58fe5d2266b6..ba1eda8f767f 100644 --- a/desktop/test/deployment/passive/passive_python.py +++ b/desktop/test/deployment/passive/passive_python.py @@ -75,8 +75,8 @@ class Dispatch(unohelper.Base, XServiceInfo, XDispatch): "com.sun.star.frame.Desktop", self.context). \ getCurrentFrame().getComponentWindow(), \ INFOBOX, BUTTONS_OK, "passive", "python") - box.execute(); - box.dispose(); + box.execute() + box.dispose() def addStatusListener(self, Control, URL): pass diff --git a/external/nss/nsinstall.py b/external/nss/nsinstall.py index d90a85e6c540..26114ef5db17 100644 --- a/external/nss/nsinstall.py +++ b/external/nss/nsinstall.py @@ -91,7 +91,7 @@ def nsinstall(argv): # It causes problems with updating the files during a rebuild. if options.m == 0o444: options.m = 0o644 - except: + except Exception: sys.stderr.write('nsinstall: ' + options.m + ' is not a valid mode\n') return 1 diff --git a/filter/source/svg/gentoken.py b/filter/source/svg/gentoken.py index 2ef75fe5dd80..4cb7a811d427 100644 --- a/filter/source/svg/gentoken.py +++ b/filter/source/svg/gentoken.py @@ -45,9 +45,9 @@ hxx.write("#ifndef INCLUDED_AUTOGEN_TOKEN_HXX\n") hxx.write("#define INCLUDED_AUTOGEN_TOKEN_HXX\n\n") hxx.write("#include \n\n" ) -i = 0; +i = 0 for token in sorted(tokens.keys()): - i += 1; + i += 1 hxx.write("const sal_Int32 {} = {};\n".format(tokens[token], i)) gperf.write("{},{}\n".format(token, tokens[token])) diff --git a/filter/source/svg/js2hxx.py b/filter/source/svg/js2hxx.py index 38bcab12b417..d10e29787a70 100755 --- a/filter/source/svg/js2hxx.py +++ b/filter/source/svg/js2hxx.py @@ -18,7 +18,8 @@ # # For minor contributions see the git repository. -import os, sys +import os +import sys MAX_LINES = 150 VARIABLE_NAME = 'aSVGScript' diff --git a/librelogo/source/LibreLogo/LibreLogo.py b/librelogo/source/LibreLogo/LibreLogo.py index 44daaeb00767..e018d33ebdd1 100644 --- a/librelogo/source/LibreLogo/LibreLogo.py +++ b/librelogo/source/LibreLogo/LibreLogo.py @@ -16,6 +16,48 @@ import traceback import itertools import threading import time as __time__ +from math import pi, sin, cos, asin, hypot + +from com.sun.star.awt import Point as __Point__ +from com.sun.star.awt import Gradient as __Gradient__ +from com.sun.star.awt.GradientStyle import LINEAR as __GradientStyle_LINEAR__ +from com.sun.star.drawing import LineDash as __LineDash__ +from com.sun.star.drawing import Hatch as __Hatch__ +from com.sun.star.drawing import PolyPolygonBezierCoords as __Bezier__ +from com.sun.star.text.TextContentAnchorType import AT_PAGE as __AT_PAGE__ +from com.sun.star.text.WrapTextMode import THROUGH as __THROUGH__ +from com.sun.star.drawing.LineCap import BUTT as __Cap_NONE__ +from com.sun.star.drawing.LineCap import ROUND as __Cap_ROUND__ +from com.sun.star.drawing.LineCap import SQUARE as __Cap_SQUARE__ +from com.sun.star.drawing.LineJoint import NONE as __Joint_NONE__ +from com.sun.star.drawing.LineJoint import BEVEL as __BEVEL__ +from com.sun.star.drawing.LineJoint import MITER as __MITER__ +from com.sun.star.drawing.LineJoint import ROUND as __ROUNDED__ +from com.sun.star.drawing.FillStyle import NONE as __FillStyle_NONE__ +from com.sun.star.drawing.FillStyle import GRADIENT as __FillStyle_GRADIENT__ +from com.sun.star.drawing.LineStyle import NONE as __LineStyle_NONE__ +from com.sun.star.drawing.LineStyle import SOLID as __LineStyle_SOLID__ +from com.sun.star.drawing.LineStyle import DASH as __LineStyle_DASHED__ +from com.sun.star.drawing.DashStyle import RECT as __DashStyle_RECT__ +from com.sun.star.drawing.CircleKind import FULL as __FULL__ +from com.sun.star.drawing.CircleKind import SECTION as __SECTION__ +from com.sun.star.drawing.CircleKind import CUT as __CUT__ +from com.sun.star.drawing.CircleKind import ARC as __ARC__ +from com.sun.star.awt.FontSlant import NONE as __Slant_NONE__ +from com.sun.star.awt.FontSlant import ITALIC as __Slant_ITALIC__ +from com.sun.star.awt.FontUnderline import SINGLE as __Underline_SINGLE__ +from com.sun.star.awt.FontStrikeout import SINGLE as __Strikeout_SINGLE__ +from com.sun.star.awt import Size as __Size__ +from com.sun.star.awt import WindowDescriptor as __WinDesc__ +from com.sun.star.awt.WindowClass import MODALTOP as __MODALTOP__ +from com.sun.star.awt.VclWindowPeerAttribute import OK as __OK__ +from com.sun.star.awt.VclWindowPeerAttribute import OK_CANCEL as __OK_CANCEL__ +from com.sun.star.awt.VclWindowPeerAttribute import YES_NO_CANCEL as __YES_NO_CANCEL__ # OK_CANCEL, YES_NO, RETRY_CANCEL, DEF_OK, DEF_CANCEL, DEF_RETRY, DEF_YES, DEF_NO +from com.sun.star.awt.PushButtonType import OK as __Button_OK__ +from com.sun.star.awt.PushButtonType import CANCEL as __Button_CANCEL__ +from com.sun.star.util.MeasureUnit import APPFONT as __APPFONT__ +from com.sun.star.beans import PropertyValue as __property__ +from com.sun.star.lang import Locale __lng__ = {} @@ -28,22 +70,22 @@ def __l12n__(lng): global __lng_fallback__ try: return __lng__[lng] - except: + except Exception: try: # load resource file __lng__[lng] = dict([[i.decode("unicode-escape").split("=")[0].strip(), i.decode("unicode-escape").split("=")[1].strip().strip("|")] for i in open(__lngpath__ + "LibreLogo_" + lng + ".properties", 'rb').readlines() if b"=" in i]) return __lng__[lng] - except: + except Exception: try: # or use embedded fallback resource dictionary __lng__[lng] = {} for i in __lng_fallback__: try: __lng__[lng][i] = __lng_fallback__[i][lng] - except: + except Exception: try: __lng__[lng][i] = __lng_fallback__[i][lng.split('_')[0]] - except: + except Exception: __lng__[lng][i] = __lng_fallback__[i]["en_US"] return __lng__[lng] except Exception: @@ -52,7 +94,7 @@ def __l12n__(lng): try: urebootstrap = os.environ["URE_BOOTSTRAP"] -except: +except Exception: # starting in command line updates embedded fallback language dictionary print("Update fallback language resource using property file arguments") for i in sys.argv[1:]: @@ -168,7 +210,7 @@ class __Doc__: self.secure = False try: self.drawpage = doc.DrawPage # Writer - except: + except Exception: self.drawpage = doc.DrawPages.getByIndex(0) # Draw, Impress self.shapecache = {} self.shapecount = itertools.count() @@ -201,49 +243,6 @@ class __Doc__: self.fontstyle = 0 self.points = [] -from math import pi, sin, cos, asin, hypot - -from com.sun.star.awt import Point as __Point__ -from com.sun.star.awt import Gradient as __Gradient__ -from com.sun.star.awt.GradientStyle import LINEAR as __GradientStyle_LINEAR__ -from com.sun.star.drawing import LineDash as __LineDash__ -from com.sun.star.drawing import Hatch as __Hatch__ -from com.sun.star.drawing import PolyPolygonBezierCoords as __Bezier__ -from com.sun.star.text.TextContentAnchorType import AT_PAGE as __AT_PAGE__ -from com.sun.star.text.WrapTextMode import THROUGH as __THROUGH__ -from com.sun.star.drawing.LineCap import BUTT as __Cap_NONE__ -from com.sun.star.drawing.LineCap import ROUND as __Cap_ROUND__ -from com.sun.star.drawing.LineCap import SQUARE as __Cap_SQUARE__ -from com.sun.star.drawing.LineJoint import NONE as __Joint_NONE__ -from com.sun.star.drawing.LineJoint import BEVEL as __BEVEL__ -from com.sun.star.drawing.LineJoint import MITER as __MITER__ -from com.sun.star.drawing.LineJoint import ROUND as __ROUNDED__ -from com.sun.star.drawing.FillStyle import NONE as __FillStyle_NONE__ -from com.sun.star.drawing.FillStyle import GRADIENT as __FillStyle_GRADIENT__ -from com.sun.star.drawing.LineStyle import NONE as __LineStyle_NONE__ -from com.sun.star.drawing.LineStyle import SOLID as __LineStyle_SOLID__ -from com.sun.star.drawing.LineStyle import DASH as __LineStyle_DASHED__ -from com.sun.star.drawing.DashStyle import RECT as __DashStyle_RECT__ -from com.sun.star.drawing.CircleKind import FULL as __FULL__ -from com.sun.star.drawing.CircleKind import SECTION as __SECTION__ -from com.sun.star.drawing.CircleKind import CUT as __CUT__ -from com.sun.star.drawing.CircleKind import ARC as __ARC__ -from com.sun.star.awt.FontSlant import NONE as __Slant_NONE__ -from com.sun.star.awt.FontSlant import ITALIC as __Slant_ITALIC__ -from com.sun.star.awt.FontUnderline import SINGLE as __Underline_SINGLE__ -from com.sun.star.awt.FontStrikeout import SINGLE as __Strikeout_SINGLE__ -from com.sun.star.awt import Size as __Size__ -from com.sun.star.awt import WindowDescriptor as __WinDesc__ -from com.sun.star.awt.WindowClass import MODALTOP as __MODALTOP__ -from com.sun.star.awt.VclWindowPeerAttribute import OK as __OK__ -from com.sun.star.awt.VclWindowPeerAttribute import OK_CANCEL as __OK_CANCEL__ -from com.sun.star.awt.VclWindowPeerAttribute import YES_NO_CANCEL as __YES_NO_CANCEL__ # OK_CANCEL, YES_NO, RETRY_CANCEL, DEF_OK, DEF_CANCEL, DEF_RETRY, DEF_YES, DEF_NO -from com.sun.star.awt.PushButtonType import OK as __Button_OK__ -from com.sun.star.awt.PushButtonType import CANCEL as __Button_CANCEL__ -from com.sun.star.util.MeasureUnit import APPFONT as __APPFONT__ -from com.sun.star.beans import PropertyValue as __property__ -from com.sun.star.lang import Locale - def __getprop__(name, value): p, p.Name, p.Value = __property__(), name, value return p @@ -283,7 +282,7 @@ def __getdocument__(): doc = XSCRIPTCONTEXT.getDocument() # noqa: F821 try: _ = __docs__[doc.RuntimeUID] - except: + except Exception: _ = __Doc__(doc) __docs__[doc.RuntimeUID] = _ @@ -303,7 +302,7 @@ def Input(s): # label l = d.createInstance("com.sun.star.awt.UnoControlFixedTextModel" ) - if type(s) == list: + if type(s) is list: s = s[0] l.PositionX, l.PositionY, l.Width, l.Height, l.Name, l.TabIndex, l.Label = 5, 4, 140, 14, "l1", 2, s @@ -351,7 +350,7 @@ def Input(s): def __string__(s, decimal = None): # convert decimal sign, localized BOOL and SET if not decimal: decimal = _.decimal - if decimal == ',' and type(s) == float: + if decimal == ',' and type(s) is float: return str(s).replace(".", ",") if type(s) in [list, tuple, dict, set]: s = re.sub("(?u)(['\"])(([^'\"]|\\['\"])*)(?= 5: + if type(n) is list and len(n) >= 5: _.linestyle = n elif re.match(__l12n__(_.lng)['SOLID'], n, flags = re.I): _.linestyle = __LineStyle_SOLID__ @@ -1688,7 +1687,7 @@ def pencap(n = -1): def fillcolor(n = -1): if n != -1: _.areacolor = __color__(n) - if type(_.areacolor) != tuple: + if type(_.areacolor) is not tuple: _.t10y = (int(_.areacolor) >> 24) / (255.0/100) else: _.t10y = 0 @@ -1703,8 +1702,8 @@ def filltransparency(n = -1): if n != -1: if n == u'any': n = 100 * random.random() - if type(n) != list: - if type(_.areacolor) != tuple: + if type(n) is not list: + if type(_.areacolor) is not tuple: fillcolor((_.areacolor & 0xffffff) + (int(n * (255.0/100)) << 24)) else: _.t10y = n @@ -1848,12 +1847,12 @@ def __groupend__(name = ""): __removeshape__(__ACTUAL__) def __int__(x): # handle eg. int("10cm") - if type(x) == str: + if type(x) is str: x = __float__(x) return int(x) def __float__(x): # handle eg. float("10,5cm") - if type(x) == str: + if type(x) is str: for i in __comp__[_.lng]: x = re.sub(u"(?iu)" + i[0], i[1], x) x = eval(x) @@ -2108,11 +2107,11 @@ def __compil__(s): try: _.lng = loc.Language + '_' + loc.Country __loadlang__(_.lng, __l12n__(_.lng)) - except: + except Exception: __trace__() _.lng = loc.Language __loadlang__(_.lng, __l12n__(_.lng)) - except: + except Exception: __trace__() # for testing compiling, we create a not document based namespace if "_" not in locals(): @@ -2270,7 +2269,7 @@ def __gotoline__(n): _.cursor.gotoNextParagraph(False) try: _.doc.CurrentController.getViewCursor().gotoRange(_.cursor, False) - except: + except Exception: __dispatcher__(".uno:Escape") _.doc.CurrentController.getViewCursor().gotoRange(_.cursor.getStart(), False)