diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62ffc2438b7..98537bb725f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,6 +43,18 @@ repos: - --license-filepath - .github/workflows/license-templates/LICENSE.txt - --fuzzy-match-generates-todo + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 25.9.0 + hooks: + - id: black + name: run black + description: format Python files with black + files: + (?x)^( + main/pyuno/demo/swriter\.py| + main/solenv/inc/lldb4aoo\.py| + main/ucb/source/ucp/ftp/test\.py + )$ - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: diff --git a/main/pyuno/demo/swriter.py b/main/pyuno/demo/swriter.py index 5632e96867c..f12896856e9 100644 --- a/main/pyuno/demo/swriter.py +++ b/main/pyuno/demo/swriter.py @@ -31,58 +31,60 @@ from com.sun.star.awt import Size -def insertTextIntoCell( table, cellName, text, color ): - tableText = table.getCellByName( cellName ) +def insertTextIntoCell(table, cellName, text, color): + tableText = table.getCellByName(cellName) cursor = tableText.createTextCursor() - cursor.setPropertyValue( "CharColor", color ) - tableText.setString( text ) + cursor.setPropertyValue("CharColor", color) + tableText.setString(text) + localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext( - "com.sun.star.bridge.UnoUrlResolver", localContext ) + "com.sun.star.bridge.UnoUrlResolver", localContext +) -smgr = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" ) -remoteContext = smgr.getPropertyValue( "DefaultContext" ) +smgr = resolver.resolve( + "uno:socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" +) +remoteContext = smgr.getPropertyValue("DefaultContext") -#remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) -#smgr = remoteContext.ServiceManager +# remoteContext = resolver.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" ) +# smgr = remoteContext.ServiceManager -desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext) +desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", remoteContext) # open a writer document -doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () ) +doc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ()) text = doc.Text cursor = text.createTextCursor() -text.insertString( cursor, "The first line in the newly created text document.\n", 0 ) -text.insertString( cursor, "Now we are in the second line.\n" , 0 ) +text.insertString(cursor, "The first line in the newly created text document.\n", 0) +text.insertString(cursor, "Now we are in the second line.\n", 0) # create a text table -table = doc.createInstance( "com.sun.star.text.TextTable" ) +table = doc.createInstance("com.sun.star.text.TextTable") # with 4 rows and 4 columns -table.initialize( 4,4) +table.initialize(4, 4) -text.insertTextContent( cursor, table, 0 ) +text.insertTextContent(cursor, table, 0) rows = table.Rows -table.setPropertyValue( "BackTransparent", uno.Bool(0) ) -table.setPropertyValue( "BackColor", 13421823 ) +table.setPropertyValue("BackTransparent", uno.Bool(0)) +table.setPropertyValue("BackColor", 13421823) row = rows.getByIndex(0) -row.setPropertyValue( "BackTransparent", uno.Bool(0) ) -row.setPropertyValue( "BackColor", 6710932 ) +row.setPropertyValue("BackTransparent", uno.Bool(0)) +row.setPropertyValue("BackColor", 6710932) textColor = 16777215 -insertTextIntoCell( table, "A1", "FirstColumn", textColor ) -insertTextIntoCell( table, "B1", "SecondColumn", textColor ) -insertTextIntoCell( table, "C1", "ThirdColumn", textColor ) -insertTextIntoCell( table, "D1", "SUM", textColor ) +insertTextIntoCell(table, "A1", "FirstColumn", textColor) +insertTextIntoCell(table, "B1", "SecondColumn", textColor) +insertTextIntoCell(table, "C1", "ThirdColumn", textColor) +insertTextIntoCell(table, "D1", "SUM", textColor) -values = ( (22.5,21.5,121.5), - (5615.3,615.3,-615.3), - (-2315.7,315.7,415.7) ) +values = ((22.5, 21.5, 121.5), (5615.3, 615.3, -615.3), (-2315.7, 315.7, 415.7)) table.getCellByName("A2").setValue(22.5) table.getCellByName("B2").setValue(5615.3) table.getCellByName("C2").setValue(-2315.7) @@ -99,27 +101,31 @@ def insertTextIntoCell( table, cellName, text, color ): table.getCellByName("D4").setFormula("sum ") -cursor.setPropertyValue( "CharColor", 255 ) -cursor.setPropertyValue( "CharShadowed", uno.Bool(1) ) +cursor.setPropertyValue("CharColor", 255) +cursor.setPropertyValue("CharShadowed", uno.Bool(1)) -text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) -text.insertString( cursor, " This is a colored text - blue with shadow\n" , 0 ) -text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) +text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0) +text.insertString(cursor, " This is a colored text - blue with shadow\n", 0) +text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0) -textFrame = doc.createInstance( "com.sun.star.text.TextFrame" ) -textFrame.setSize( Size(15000,400)) -textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER ) +textFrame = doc.createInstance("com.sun.star.text.TextFrame") +textFrame.setSize(Size(15000, 400)) +textFrame.setPropertyValue("AnchorType", AS_CHARACTER) -text.insertTextContent( cursor, textFrame, 0 ) +text.insertTextContent(cursor, textFrame, 0) textInTextFrame = textFrame.getText() cursorInTextFrame = textInTextFrame.createTextCursor() -textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 ) -textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the frame raises.",0) -text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 ) - -cursor.setPropertyValue( "CharColor", 65536 ) -cursor.setPropertyValue( "CharShadowed", uno.Bool(0) ) - -text.insertString( cursor, " That's all for now!" , 0 ) +textInTextFrame.insertString( + cursorInTextFrame, "The first line in the newly created text frame.", 0 +) +textInTextFrame.insertString( + cursorInTextFrame, "\nWith this second line the height of the frame raises.", 0 +) +text.insertControlCharacter(cursor, PARAGRAPH_BREAK, 0) + +cursor.setPropertyValue("CharColor", 65536) +cursor.setPropertyValue("CharShadowed", uno.Bool(0)) + +text.insertString(cursor, " That's all for now!", 0) diff --git a/main/solenv/inc/lldb4aoo.py b/main/solenv/inc/lldb4aoo.py index 7b193a209d8..ace3d76cf43 100644 --- a/main/solenv/inc/lldb4aoo.py +++ b/main/solenv/inc/lldb4aoo.py @@ -16,106 +16,132 @@ # under the License. # to activate the AOO-LLDB helper script type the line below into LLDB -# command script import path-to-script/lldb4aoo.py +# command script import path-to-script/lldb4aoo.py # or activate it automatically by adding the line to ~/.lldbinit -def __lldb_init_module( dbg, dict): - # the list of AOO specific types - aoo_types = ['rtl_String', 'rtl_uString', '_ByteStringData', '_UniStringData'] - pimpl_types = ['rtl::OString', 'rtl::OUString', 'ByteString', 'UniString'] - # register a helper function for each non-trivial type - for t in aoo_types: - f = 'getinfo_for_' + t.replace( '::', '_') - if f in globals(): - dbg.HandleCommand( 'type summary add %s -v -C yes -F %s.%s' % (t,__name__,f)) - else: - print( 'AOO-LLDB helper function "%s" is not yet defined: ' - '"%s" types cannot be displayed properly!' % (f,t)) - # register a generic helper function for pimpl types - dbg.HandleCommand( 'type summary add -F %s.%s -v -C yes -n PIMPL %s' % ( __name__,'get_pimpl_info', ' '.join(pimpl_types))) - - # add info about specific helper methods - # assume functions with docstrings are available for general consumption - helper_funcs = [v for (k,v) in globals().iteritems() if( not k.startswith('_') and callable(v) and v.__doc__)] - if helper_funcs: - print( 'Available AOO-specific helper functions:') - for hfunc in helper_funcs: - shortdesc = hfunc.__doc__.splitlines()[0] - print( '\t%s\t# "%s"' %(hfunc.__name__, shortdesc)) - print( 'Run them with:') - for hfunc in helper_funcs[:4]: - print( '\tscript %s.%s()' %(__name__, hfunc.__name__)) + +def __lldb_init_module(dbg, dict): + # the list of AOO specific types + aoo_types = ["rtl_String", "rtl_uString", "_ByteStringData", "_UniStringData"] + pimpl_types = ["rtl::OString", "rtl::OUString", "ByteString", "UniString"] + # register a helper function for each non-trivial type + for t in aoo_types: + f = "getinfo_for_" + t.replace("::", "_") + if f in globals(): + dbg.HandleCommand( + "type summary add %s -v -C yes -F %s.%s" % (t, __name__, f) + ) + else: + print( + 'AOO-LLDB helper function "%s" is not yet defined: ' + '"%s" types cannot be displayed properly!' % (f, t) + ) + # register a generic helper function for pimpl types + dbg.HandleCommand( + "type summary add -F %s.%s -v -C yes -n PIMPL %s" + % (__name__, "get_pimpl_info", " ".join(pimpl_types)) + ) + + # add info about specific helper methods + # assume functions with docstrings are available for general consumption + helper_funcs = [ + v + for (k, v) in globals().iteritems() + if (not k.startswith("_") and callable(v) and v.__doc__) + ] + if helper_funcs: + print("Available AOO-specific helper functions:") + for hfunc in helper_funcs: + shortdesc = hfunc.__doc__.splitlines()[0] + print('\t%s\t# "%s"' % (hfunc.__name__, shortdesc)) + print("Run them with:") + for hfunc in helper_funcs[:4]: + print("\tscript %s.%s()" % (__name__, hfunc.__name__)) + # some helpers for use from interactive LLDB sessions import lldb + def add_breakpoints(): - 'Setup breakpoints useful for AOO debugging' - dbg = lldb.debugger - if dbg.GetNumTargets() == 0: - return - # the list of interesting function breakpoints - aoo_breakfn = ['main', '__cxa_call_unexpected', 'objc_exception_throw'] - aoo_breakfn += ['__cxa_throw'] - # register breakpoints for function basenames - for b in aoo_breakfn: - dbg.HandleCommand( 'breakpoint set -b ' + b) + "Setup breakpoints useful for AOO debugging" + dbg = lldb.debugger + if dbg.GetNumTargets() == 0: + return + # the list of interesting function breakpoints + aoo_breakfn = ["main", "__cxa_call_unexpected", "objc_exception_throw"] + aoo_breakfn += ["__cxa_throw"] + # register breakpoints for function basenames + for b in aoo_breakfn: + dbg.HandleCommand("breakpoint set -b " + b) # local functions for use by the AOO-type summary providers -def walk_ptrchain( v): - info = '' - while v.TypeIsPointerType(): - n = v.GetValueAsUnsigned() - if n == 0: - info += 'NULL' - return (None, info) - info += '0x%04X-> ' % (n) - v = v.Dereference() - return (v, info) - -def ret_strdata_info( v, refvar, lenvar, aryvar): - (v, info) = walk_ptrchain( v) - if not v: - return info - r = v.GetChildMemberWithName( refvar).GetValueAsSigned() - l = v.GetChildMemberWithName( lenvar).GetValueAsSigned() - c = v.GetChildMemberWithName( aryvar) - if (r < 0) or (l < 0): - info += 'CORRUPT_STR={refs=%d, len=%d}' % (r,l) - return info - L = min(l,128) - d = c.AddressOf().GetPointeeData( 0, L) - if c.GetByteSize() == 1: # assume UTF-8 - s = ''.join([chr(x) for x in d.uint8s]) - else: # assume UTF-16 - s = (u''.join([unichr(x) for x in d.uint16s])).encode('utf-8') - info += ('{refs=%d, len=%d, str="%s"%s}' % (r, l, s.encode('string_escape'), '...'if(l!=L)else'')) - return info + +def walk_ptrchain(v): + info = "" + while v.TypeIsPointerType(): + n = v.GetValueAsUnsigned() + if n == 0: + info += "NULL" + return (None, info) + info += "0x%04X-> " % (n) + v = v.Dereference() + return (v, info) + + +def ret_strdata_info(v, refvar, lenvar, aryvar): + (v, info) = walk_ptrchain(v) + if not v: + return info + r = v.GetChildMemberWithName(refvar).GetValueAsSigned() + l = v.GetChildMemberWithName(lenvar).GetValueAsSigned() + c = v.GetChildMemberWithName(aryvar) + if (r < 0) or (l < 0): + info += "CORRUPT_STR={refs=%d, len=%d}" % (r, l) + return info + L = min(l, 128) + d = c.AddressOf().GetPointeeData(0, L) + if c.GetByteSize() == 1: # assume UTF-8 + s = "".join([chr(x) for x in d.uint8s]) + else: # assume UTF-16 + s = ("".join([unichr(x) for x in d.uint16s])).encode("utf-8") + info += '{refs=%d, len=%d, str="%s"%s}' % ( + r, + l, + s.encode("string_escape"), + "..." if (l != L) else "", + ) + return info + # definitions for our individual LLDB type summary providers -def get_pimpl_info( valobj, dict): - (v, info) = walk_ptrchain( valobj) - p = v.GetChildAtIndex(0) - pname = p.GetName() - n = p.GetValueAsUnsigned() - if n == 0: - return '%s(%s==NULL)' % (info, pname) - info = '%s(%s=0x%04X)-> ' % (info, pname, n) - return info + p.Dereference().GetSummary() +def get_pimpl_info(valobj, dict): + (v, info) = walk_ptrchain(valobj) + p = v.GetChildAtIndex(0) + pname = p.GetName() + n = p.GetValueAsUnsigned() + if n == 0: + return "%s(%s==NULL)" % (info, pname) + info = "%s(%s=0x%04X)-> " % (info, pname, n) + return info + p.Dereference().GetSummary() + + +def getinfo_for_rtl_String(valobj, dict): + return ret_strdata_info(valobj, "refCount", "length", "buffer") + + +def getinfo_for_rtl_uString(valobj, dict): + return ret_strdata_info(valobj, "refCount", "length", "buffer") -def getinfo_for_rtl_String( valobj, dict): - return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') -def getinfo_for_rtl_uString( valobj, dict): - return ret_strdata_info( valobj, 'refCount', 'length', 'buffer') +def getinfo_for__ByteStringData(valobj, dict): + return ret_strdata_info(valobj, "mnRefCount", "mnLen", "maStr") -def getinfo_for__ByteStringData( valobj, dict): - return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') -def getinfo_for__UniStringData( valobj, dict): - return ret_strdata_info( valobj, 'mnRefCount', 'mnLen', 'maStr') +def getinfo_for__UniStringData(valobj, dict): + return ret_strdata_info(valobj, "mnRefCount", "mnLen", "maStr") diff --git a/main/ucb/source/ucp/ftp/test.py b/main/ucb/source/ucp/ftp/test.py index 86c92d27538..bd41ccf6644 100644 --- a/main/ucb/source/ucp/ftp/test.py +++ b/main/ucb/source/ucp/ftp/test.py @@ -1,4 +1,4 @@ -#/usr/bin/env python +# /usr/bin/env python # ************************************************************* # # Licensed to the Apache Software Foundation (ASF) under one @@ -20,26 +20,28 @@ # # ************************************************************* -import re,os +import re, os -def grep(pattern,dirname,names): - for name in names: - filename = os.path.join(dirname,name) - if os.path.isfile(filename): - lines = open(filename,"r").readlines() - for line in lines: - if pattern.search(line): - print(filename) - break +def grep(pattern, dirname, names): + for name in names: + filename = os.path.join(dirname, name) + if os.path.isfile(filename): + lines = open(filename, "r").readlines() + for line in lines: + if pattern.search(line): + print(filename) + break -def find(pattern,directory = "."): - os.path.walk(directory,grep,re.compile(pattern)) + +def find(pattern, directory="."): + os.path.walk(directory, grep, re.compile(pattern)) if __name__ == "__main__": - import sys - if len(sys.argv) == 2: - find(sys.argv[1]) - elif len(sys.argv) == 2: - find(sys.argv[2],sys.argv[1]) + import sys + + if len(sys.argv) == 2: + find(sys.argv[1]) + elif len(sys.argv) == 2: + find(sys.argv[2], sys.argv[1])