pythonscript.py (b5f289e3) pythonscript.py (b4375c20)
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 42 unchanged lines hidden (view full) ---

51# True, writes to stdout (difficult on windows)
52# False, writes to user/Scripts/python/log.txt
53LOG_STDOUT = os.environ.get(PYSCRIPT_LOG_STDOUT_ENV, "1") != "0"
54
55ENABLE_EDIT_DIALOG=False # offers a minimal editor for editing.
56#-------------------------------------------------------------------
57
58def encfile(uni):
1# *************************************************************
2#
3# Licensed to the Apache Software Foundation (ASF) under one
4# or more contributor license agreements. See the NOTICE file
5# distributed with this work for additional information
6# regarding copyright ownership. The ASF licenses this file
7# to you under the Apache License, Version 2.0 (the
8# "License"); you may not use this file except in compliance

--- 42 unchanged lines hidden (view full) ---

51# True, writes to stdout (difficult on windows)
52# False, writes to user/Scripts/python/log.txt
53LOG_STDOUT = os.environ.get(PYSCRIPT_LOG_STDOUT_ENV, "1") != "0"
54
55ENABLE_EDIT_DIALOG=False # offers a minimal editor for editing.
56#-------------------------------------------------------------------
57
58def encfile(uni):
59 return uni.encode( sys.getfilesystemencoding())
59 if sys.version_info[0] > 2:
60 return uni
61 else:
62 return uni.encode( sys.getfilesystemencoding())
60
61def lastException2String():
62 (excType,excInstance,excTraceback) = sys.exc_info()
63 ret = str(excType) + ": "+str(excInstance) + "\n" + \
64 uno._uno_extract_printable_stacktrace( excTraceback )
65 return ret
66
67def logLevel2String( level ):

--- 8 unchanged lines hidden (view full) ---

76 ret = sys.stdout
77 if not LOG_STDOUT:
78 try:
79 pathSubst = uno.getComponentContext().ServiceManager.createInstance(
80 "com.sun.star.util.PathSubstitution" )
81 userInstallation = pathSubst.getSubstituteVariableValue( "user" )
82 if len( userInstallation ) > 0:
83 systemPath = uno.fileUrlToSystemPath( userInstallation + "/Scripts/python/log.txt" )
63
64def lastException2String():
65 (excType,excInstance,excTraceback) = sys.exc_info()
66 ret = str(excType) + ": "+str(excInstance) + "\n" + \
67 uno._uno_extract_printable_stacktrace( excTraceback )
68 return ret
69
70def logLevel2String( level ):

--- 8 unchanged lines hidden (view full) ---

79 ret = sys.stdout
80 if not LOG_STDOUT:
81 try:
82 pathSubst = uno.getComponentContext().ServiceManager.createInstance(
83 "com.sun.star.util.PathSubstitution" )
84 userInstallation = pathSubst.getSubstituteVariableValue( "user" )
85 if len( userInstallation ) > 0:
86 systemPath = uno.fileUrlToSystemPath( userInstallation + "/Scripts/python/log.txt" )
84 ret = file( systemPath , "a" )
87 ret = open( systemPath , "a" )
85 except Exception as e:
86 print("Exception during creation of pythonscript logfile: "+ lastException2String() + "\n, delagating log to stdout\n")
87 return ret
88
89class Logger(LogLevel):
90 def __init__(self , target ):
91 self.target = target
92

--- 55 unchanged lines hidden (view full) ---

148g_ImplementationHelper = unohelper.ImplementationHelper()
149g_implName = "org.openoffice.pyuno.LanguageScriptProviderFor"+LANGUAGENAME
150
151
152
153BLOCK_SIZE = 65536
154def readTextFromStream( inputStream ):
155 # read the file
88 except Exception as e:
89 print("Exception during creation of pythonscript logfile: "+ lastException2String() + "\n, delagating log to stdout\n")
90 return ret
91
92class Logger(LogLevel):
93 def __init__(self , target ):
94 self.target = target
95

--- 55 unchanged lines hidden (view full) ---

151g_ImplementationHelper = unohelper.ImplementationHelper()
152g_implName = "org.openoffice.pyuno.LanguageScriptProviderFor"+LANGUAGENAME
153
154
155
156BLOCK_SIZE = 65536
157def readTextFromStream( inputStream ):
158 # read the file
156 code = uno.ByteSequence( "" )
159 code = uno.ByteSequence( b"" )
157 while True:
158 read,out = inputStream.readBytes( None , BLOCK_SIZE )
159 code = code + out
160 if read < BLOCK_SIZE:
161 break
160 while True:
161 read,out = inputStream.readBytes( None , BLOCK_SIZE )
162 code = code + out
163 if read < BLOCK_SIZE:
164 break
162 return code.value
165 if sys.version_info[0] > 2:
166 return str( code.value, 'utf-8' )
167 else:
168 return code.value
163
164def toIniName( str ):
165 # TODO: what is the official way to get to know whether i am on the windows platform ?
166 if( hasattr(sys , "dllhandle") ):
167 return str + ".ini"
168 return str + "rc"
169
170

--- 904 unchanged lines hidden ---
169
170def toIniName( str ):
171 # TODO: what is the official way to get to know whether i am on the windows platform ?
172 if( hasattr(sys , "dllhandle") ):
173 return str + ".ini"
174 return str + "rc"
175
176

--- 904 unchanged lines hidden ---