Open in CoCalc
1
# This file was *autogenerated* from the file utils_sys.sage
2
from sage.all_cmdline import * # import sage library
3
_sage_const_3 = Integer(3); _sage_const_2 = Integer(2); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_5 = Integer(5); _sage_const_4 = Integer(4); _sage_const_1000 = Integer(1000)####################################################################################################
4
# This module contains utilities for using system routines
5
# These are functions for Debug-Logging and formatted docstring output
6
####################################################################################################
7
8
9
10
11
from lib.enum import Enum
12
from datetime import datetime
13
import traceback
14
import sys
15
16
17
# --------------------------------------------------------------------------------------
18
# Constants
19
# --------------------------------------------------------------------------------------
20
21
class TsLevel(Enum):
22
Silent = _sage_const_0
23
StackInfo = _sage_const_1
24
Body = _sage_const_2
25
BodySub1 = _sage_const_3
26
BodySub2 = _sage_const_4
27
Debug = _sage_const_5
28
29
30
31
def print_time_tb( Text="", Info="", MaxDepth = _sage_const_1 , Offset = _sage_const_1 , Level = TsLevel.Silent, ShowDateTime = True ):
32
"""
33
This is a utility to implement a time-stamp debugging in any function
34
Whenever this function is called it prints the actual timestamp together with traceback information.
35
36
37
If you don't see this well formatted type
38
39
sage: print print_time_tb.__doc__
40
41
42
INPUT (all optional keywords):
43
44
- "Text": string describing the code position
45
46
- "Info": string containing further information (for instance on elapse time)
47
48
- "MaxDepth": integer representing the number of traceback steps (top down) to be printed
49
50
- "Offset": integer representing the number of traceback steps (top down) to be ignored
51
52
- "Level": Constants with integer value (substitutes enum type): classifies the position of invocation. The
53
following values are possible:
54
55
constant integer usage
56
--------------------------------------------------------------------------------------------------
57
TsLevel.Silent: 0, a message to be printed always
58
TsLevel.StackInfo: 1, indicating function / method entry or exit. typical Text = "Begin", "End"
59
TsLevel.Body: 2, indicating a position in the Body of a function / method
60
TsLevel.BodySub1: 3, similar to the former but subordinary to it
61
TsLevel.BodySub2: 4, similar to the former but subordinary to it
62
TsLevel.Debug: 5, Debug message
63
64
- "ShowDateTime": boolean (Default = True). If set to False the date and time part of the message is supressed
65
66
OUTPUT:
67
68
only prints, no return value
69
70
EXAMPLES:
71
72
sage: print_time_tb( Text="Hello", Info="Test" )
73
L: Silent Time 2016-10-06 18:30:22.574296 Test Hello In: <module> Line: 1
74
sage:
75
76
using the Level option
77
78
sage: print_time_tb( Text="Hello", Info="Test", Level = TsLevel.StackInfo )
79
L: StackInfo Time 2016-10-06 18:31:58.569208 Test Hello In: <module> Line: 1
80
sage:
81
82
using the MaxDepth option
83
84
sage:
85
sage: print_time_tb( Text="Hello", Info="Test", MaxDepth = 2, Level = TsLevel.StackInfo )
86
L: StackInfo Time 2016-10-06 18:32:21.537412 Test Hello In: <module> Line: 1
87
---> run_code In: /opt/sage/sage-6.9-i686-Linux/local/lib/python2.7/site-packages/IPython/core/
88
interactiveshell.py Line: 3066
89
sage: print_time_tb( Text="Hello", Info="Test", MaxDepth = 3, Level = TsLevel.StackInfo )
90
L: StackInfo Time 2016-10-06 18:32:31.292799 Test Hello In: <module> Line: 1
91
---> run_code In: /opt/sage/sage-6.9-i686-Linux/local/lib/python2.7/site-packages/IPython/core/
92
interactiveshell.py Line: 3066
93
---> run_ast_nodes In: /opt/sage/sage-6.9-i686-Linux/local/lib/python2.7/site-packages/IPython/core/
94
interactiveshell.py Line: 3012
95
96
using the Offset option
97
98
sage: print_time_tb( Text="Hello", Info="Test", MaxDepth = 3, Offset = 2, Level = TsLevel.StackInfo )
99
L: StackInfo Time 2016-10-06 18:33:20.339336 Test Hello In: run_code Line: 3066
100
---> run_ast_nodes In: /opt/sage/sage-6.9-i686-Linux/local/lib/python2.7/site-packages/IPython/core/
101
interactiveshell.py Line: 3012
102
---> run_cell In: /opt/sage/sage-6.9-i686-Linux/local/lib/python2.7/site-packages/IPython/core/
103
interactiveshell.py Line: 2902
104
105
AUTHOR
106
107
- Sebastian Oehms, Oct. 2016
108
109
"""
110
111
intLevel = Level.value
112
TraceBack = traceback.extract_stack()
113
LenTb = len(TraceBack)
114
if LenTb < _sage_const_1 +Offset:
115
return
116
117
TraceBackEntry = TraceBack[LenTb-_sage_const_1 -Offset]
118
TraceBackEntryModule = TraceBackEntry[_sage_const_0 ]
119
TraceBackEntryLineNo = TraceBackEntry[_sage_const_1 ]
120
TraceBackEntryFunction = TraceBackEntry[_sage_const_2 ]
121
DateTime =''
122
if ShowDateTime == True:
123
DateTime = str(datetime.today())
124
125
print "L: %-12s: %s %s %s In: %s Line: %s"%(Level.name, DateTime, Info, Text, TraceBackEntryFunction, TraceBackEntryLineNo )
126
127
for i in range( MaxDepth -_sage_const_1 ):
128
TraceBackEntry = TraceBack[LenTb-_sage_const_2 -Offset-i]
129
TraceBackEntryModule = TraceBackEntry[_sage_const_0 ]
130
TraceBackEntryLineNo = TraceBackEntry[_sage_const_1 ]
131
TraceBackEntryFunction = TraceBackEntry[_sage_const_2 ]
132
print " --->", TraceBackEntryFunction, "In:", TraceBackEntryModule, "Line:", TraceBackEntryLineNo
133
if TraceBackEntryFunction == "<module>":
134
break
135
136
return
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
class timeStampControl:
153
"""
154
This class controls a consistent use of the print_time_tb function
155
156
If you don't see this well formatted type
157
158
sage: print timeStampControl.__doc__
159
160
to learn more about the function print_time_tb type
161
162
sage: print print_time_tb.__doc__
163
164
The printing of messages is done be the method "print_timestamp". But only those messages are printed which
165
agree with the verbose level of the "timeStampControl"-instance which can be desribed by the constructor parameters
166
- "KeepSilentOnElapse"
167
- "TimeStampLevel":
168
169
To learn more about the printing method type
170
171
sage: timeStampControl.print_timestamp.__doc__
172
173
INPUT (to the constructor):
174
175
- "KeepSilentOnElapse": integer representing milli-seconds (default is 0). If this is set to a positive value only
176
those messages are printed which firstly occur after the indicated number of milli-seconds
177
behind the former printed message
178
- "TimeStampLevel": Member of Enum-class TsLevel. For possible values see the values of
179
the Level parameter of the function (print_time_tb). To see this type
180
"sage: print print_time_tb.__doc__"
181
Default value is TsLevel.Silent meaning that only messages of Level TsLevel.Silent are printed.
182
If this is set to another value only those messages are printed, whose integer value of
183
"Level" is less or equal to "TimeStampLevel".
184
185
- "TraceBackDepth": integer representing number of lines of traceback information to be printed (top down,
186
default is 1). This parameter is passed to the corresponding parameter of the
187
print_time_tb function
188
- "Offset": integer representing number of lines of traceback information to be ignored (top down,
189
default is 1). This parameter is passed to the corresponding parameter of the
190
print_time_tb function after increasing it by one (supress the traceback information of
191
the print_timestamp method itselfe).
192
- "ShowDateTime": boolean (Default = True). If set to False the date and time part of the message is supressed
193
194
195
RAISE (on construction):
196
197
- TypeError "KeepSilentOnElapse must be of type Integer"
198
- TypeError "TraceBackDepth must be of type Integer"
199
- TypeError "Offset must be of type Integer"
200
201
- ValueError "TimeStampLevel must be a member of Enum TsLevel"
202
203
- ValueError "KeepSilentOnElapse must be non negative"
204
- ValueError "TraceBackDepth must be non negative"
205
- ValueError "Offset must be non negative"
206
207
208
209
EXAMPLES:
210
211
sage: TestTimeStampControl = timeStampControl( )
212
sage: TestTimeStampControl.print_timestamp(Text="Look")
213
L: Silent Time 2016-10-07 18:20:21.827425 Elapse: 5581, Total: 5 Look In: <module> Line: 1
214
215
using KeepSilentOnElapse:
216
217
sage: TestTimeStampControl2 = timeStampControl( KeepSilentOnElapse = 2000 )
218
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
219
L: Silent Time 2016-10-07 18:28:40.404085 Elapse: 2942, Total: 2 Look 2 In: <module> Line: 1
220
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
221
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
222
L: Silent Time 2016-10-07 18:28:43.239652 Elapse: 2848, Total: 5 (truncated 1) Look 2 In: <module> Line: 1
223
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
224
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
225
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
226
L: Silent Time 2016-10-07 18:28:45.683139 Elapse: 2443, Total: 8 (truncated 2) Look 2 In: <module> Line: 1
227
sage: TestTimeStampControl2.print_timestamp(Text="Look 2")
228
L: Silent Time 2016-10-07 18:28:47.891519 Elapse: 2208, Total: 10 Look 2 In: <module> Line: 1
229
230
using TimeStampLevel:
231
232
sage: TestTimeStampControl3 = timeStampControl( TimeStampLevel = TsLevel.StackInfo )
233
sage: def testTsLevel( ):
234
....: TestTimeStampControl3.print_timestamp(Text="Entry", Level = TsLevel.StackInfo )
235
....: TestTimeStampControl3.print_timestamp(Text="Body", Level = TsLevel.Body )
236
....: TestTimeStampControl3.print_timestamp(Text="Exit", Level = TsLevel.StackInfo )
237
....:
238
sage:
239
sage: testTsLevel()
240
L: StackInfo Time 2016-10-07 18:38:38.041593 Elapse: 39631, Total: 39 Entry In: testTsLevel Line: 2
241
L: StackInfo Time 2016-10-07 18:38:38.044064 Elapse: 4, Total: 39 Exit In: testTsLevel Line: 4
242
sage:
243
sage: TestTimeStampControl3 = timeStampControl( TimeStampLevel = TsLevel.Body )
244
sage: testTsLevel()
245
L: StackInfo Time 2016-10-07 18:50:57.921070 Elapse: 1791, Total: 1 Entry In: testTsLevel Line: 2
246
L: Body Time 2016-10-07 18:50:57.923609 Elapse: 519, Total: 2 Body In: testTsLevel Line: 3
247
L: StackInfo Time 2016-10-07 18:50:57.926158 Elapse: 2, Total: 2 Exit In: testTsLevel Line: 4
248
sage: TestTimeStampControl3 = timeStampControl( TimeStampLevel = TsLevel.Debug )
249
sage: testTsLevel()
250
L: StackInfo Time 2016-10-07 18:51:09.257619 Elapse: 1638, Total: 1 Entry In: testTsLevel Line: 2
251
L: Body Time 2016-10-07 18:51:09.260104 Elapse: 3, Total: 1 Body In: testTsLevel Line: 3
252
L: StackInfo Time 2016-10-07 18:51:09.262624 Elapse: 2, Total: 1 Exit In: testTsLevel Line: 4
253
sage:
254
255
256
AUTHOR:
257
258
- Sebastian Oehms, Oct. 2016
259
260
"""
261
def __init__( self, KeepSilentOnElapse = _sage_const_0 , TimeStampLevel = TsLevel.Silent, TraceBackDepth = _sage_const_1 , Offset = _sage_const_1 , ShowDateTime = True ):
262
"""
263
Python constructor.
264
265
for more information type
266
267
sage: print timeStampControl.__doc__
268
269
270
AUTHOR
271
272
- Sebastian Oehms, Oct. 2016
273
274
"""
275
276
277
if type( KeepSilentOnElapse ) != Integer:
278
raise TypeError( "KeepSilentOnElapse must be of type Integer" )
279
elif KeepSilentOnElapse < _sage_const_0 :
280
raise ValueError( "KeepSilentOnElapse must be non negative" )
281
282
if isinstance(TimeStampLevel, TsLevel) == False:
283
raise ValueError( "TimeStampLevel must belong to enum %s", TsLevel )
284
285
if type( TraceBackDepth ) != Integer:
286
raise TypeError( "TraceBackDepth must be of type Integer" )
287
elif TraceBackDepth < _sage_const_0 :
288
raise ValueError( "TraceBackDepth must be non negative" )
289
290
if type( Offset ) != Integer:
291
raise TypeError( "Offset must be of type Integer" )
292
elif Offset < _sage_const_0 :
293
raise ValueError( "Offset must be non negative" )
294
295
self._KeepSilentOnElapse_ = KeepSilentOnElapse
296
self._TimeStampLevel_ = TimeStampLevel
297
self._TraceBackDepth_ = TraceBackDepth
298
self._Offset_ = Offset
299
self._ShowDateTime_ = ShowDateTime
300
self._init_time_ = datetime.today()
301
self._reset_time_ = datetime.today()
302
self._last_time_ = datetime.today()
303
self._act_time_ = datetime.today()
304
self._count_ = _sage_const_0
305
306
307
308
309
310
def __reduce__(self):
311
"""
312
Checks or unity
313
314
If you don't see this well formatted type
315
316
sage: print timeStampControl.__recuce__.__doc__
317
318
EXAMPLE:
319
320
sage: TestTimeStampControl3 = timeStampControl( TimeStampLevel = TsLevel.Debug )
321
sage: TestTimeStampControl3.__reduce__()
322
(<class lib.utils_sys.timeStampControl at 0xac49398c>, (0, 'Debug', 1, 1))
323
sage:
324
"""
325
326
return (timeStampControl, (self._KeepSilentOnElapse_, self._TimeStampLevel_, self._TraceBackDepth_, self._Offset_,))
327
328
329
330
331
def _repr_( self ):
332
"""
333
Return a string representation
334
335
If you don't see this well formatted type
336
337
sage: print timeStampControl._repr_.__doc__
338
339
OUTPUT:
340
341
String decribing self
342
343
EXAMPLE:
344
345
sage: TestTimeStampControl3 = timeStampControl( TimeStampLevel = TsLevel.Debug )
346
sage: TestTimeStampControl3._repr_()
347
'TimeStampControl with KeepSilentOnElapse = 0, TimeStampLevel = Debug, TraceBackDepth = 1, Offset 1'
348
sage:
349
350
"""
351
352
return "TimeStampControl with KeepSilentOnElapse = %d, TimeStampLevel = %s, TraceBackDepth = %d, Offset %d, ShowDateTime %s"\
353
%(self._KeepSilentOnElapse_, self._TimeStampLevel_, self._TraceBackDepth_, self._Offset_, self._ShowDateTime_)
354
355
356
357
def reset(self):
358
"""
359
Reset the elapse time control counters
360
361
If you don't see this well formatted type
362
363
sage: print timeStampControl.reset.__doc__
364
365
366
EXAMPLE:
367
368
sage: TestTimeStamp = setupTimeStamp( verbose = True )
369
sage: TestTimeStamp.print_timestamp()
370
L: Silent Time 2016-10-11 18:29:04.012623 Elapse: 2307, Total: 2 In: <module> Line: 1
371
sage: TestTimeStamp.print_timestamp()
372
L: Silent Time 2016-10-11 18:29:06.321664 Elapse: 2309, Total: 4 In: <module> Line: 1
373
sage: TestTimeStamp.reset()
374
sage: TestTimeStamp.print_timestamp()
375
L: Silent Time 2016-10-11 18:29:11.679048 Elapse: 2187, Total: 2/ 9 In: <module> Line: 1
376
sage: TestTimeStamp.print_timestamp()
377
L: Silent Time 2016-10-11 18:29:14.343407 Elapse: 2665, Total: 4/ 12 In: <module> Line: 1
378
379
AUTHOR
380
381
- Sebastian Oehms, Oct. 2016
382
383
"""
384
385
self._reset_time_ = datetime.today()
386
self._last_time_ = datetime.today()
387
self._act_time_ = datetime.today()
388
self._count_ = _sage_const_0
389
390
return
391
392
393
394
395
def print_timestamp( self, Text="", Level = TsLevel.Silent ):
396
"""
397
This method prints a timestamp message depending on the parameters
398
399
- KeepSilentOnElapse
400
401
- TimeStampLevel
402
403
which have been set in the constructor of the class. It uses the function print_time_tb.
404
405
If you don't see this well formatted type
406
407
sage: print timeStampControl.print_timestamp.__doc__
408
409
to learn more about the function print_time_tb type
410
411
sage: print print_time_tb.__doc__
412
413
to learn more about the parmeters "KeepSilentOnElapse" and "TimeStampLevel" or to see examples
414
415
sage: print timeStampControl.__doc__
416
417
INPUT (all optional keyword):
418
419
- "Text": string (default empty) describing the position of invocation. This parameter is passed to
420
the corresponding parameter of print_time_tb
421
422
- "Level": Enum constants (class TsLevel) with integer value: classifies the position of invocation.
423
This parameter is passed to the corresponding parameter of print_time_tb
424
425
426
OUTPUT:
427
428
only prints, no return value
429
430
EXAMPLES:
431
432
to see examples type
433
434
sage: print timeStampControl.__doc__
435
436
AUTHOR:
437
438
- Sebastian Oehms, Oct. 2016
439
440
"""
441
442
if Level.value > self._TimeStampLevel_.value:
443
return
444
445
self._act_time_ = datetime.today()
446
elapse_time_timedelta = self._act_time_ - self._last_time_
447
total_time_timedelta = self._act_time_ - self._init_time_
448
reset_time_timedelta = self._act_time_ - self._reset_time_
449
elapse_time_msec_float = elapse_time_timedelta.total_seconds()*_sage_const_1000
450
total_time_sec_float = total_time_timedelta.total_seconds()
451
reset_time_sec_float = reset_time_timedelta.total_seconds()
452
elapse_time_msec = elapse_time_msec_float.__trunc__()
453
total_time_sec = total_time_sec_float.__trunc__()
454
reset_time_sec = reset_time_sec_float.__trunc__()
455
456
if total_time_sec > reset_time_sec:
457
if self._count_ > _sage_const_0 :
458
info_str = "Elapse: %5d, Total: %3d/%3d (truncated %3d)"%(elapse_time_msec,\
459
reset_time_sec, total_time_sec, self._count_)
460
else:
461
info_str = "Elapse: %5d, Total: %3d/%3d"%(elapse_time_msec, reset_time_sec, total_time_sec)
462
else:
463
if self._count_ > _sage_const_0 :
464
info_str = "Elapse: %5d, Total: %3d (truncated %3d)"%(elapse_time_msec, total_time_sec, self._count_)
465
else:
466
info_str = "Elapse: %5d, Total: %3d"%(elapse_time_msec, total_time_sec)
467
468
self._count_ = self._count_ +_sage_const_1
469
if self._KeepSilentOnElapse_ <= elapse_time_msec:
470
print_time_tb( Text, Info=info_str, MaxDepth = self._TraceBackDepth_, Offset = self._Offset_+_sage_const_1 ,
471
Level=Level, ShowDateTime = self._ShowDateTime_ )
472
self._last_time_ = self._act_time_
473
self._count_ = _sage_const_0
474
475
return
476
477
478
479
480
481
482
483
484
485
486
487
488
def setupTimeStamp( verbose = False, Offset = None, TraceBackDepth = None, ShowDateTime = True ):
489
"""
490
This is a function which should make the declaration of a timeStampControl instance easier.
491
It interprets the commonly used "verbose" parameter into "KeepSilentOnElapse" and "TimeStampLevel" parameters
492
of the timeStampControl class.
493
494
If you don't see this well formatted type:
495
496
sage: print setupTimeStamp.__doc__
497
498
to learn more about the timeStampControl class type:
499
500
sage: print timeStampControl.__doc__
501
502
INPUT:
503
504
- "verbose": This parameter allowes multi type input, namely a boolean, an integer, an instance of the
505
timeStanpControl class or an constant from Enum class TsLevel
506
- By default it is set to the "boolean False" meaning that only silent messages are printed.
507
- Setting it as a "boolean True" leads to printing all messages (of any level).
508
- Setting it to an integer > 0 leads to printing messages after an elapse time of the same number
509
of milli seconds after the former printed message (see the "KeepSilentOnElapse" parameter of the
510
timeStampControl class)
511
- Setting it to a member of the Enum class TsLevel leads to printing all messages whose level is not
512
larger as the Enum-Integer-Value of the level
513
- Giving an instance of the timeStampControl class performes a reset of counting variables.
514
515
- "TraceBackDepth": integer representing number of lines of traceback information to be printed (top down,
516
default is 1 if no elapse time is set, else it defaults to 4). This parameter is passed
517
to the corresponding parameter of the timeStampControl class and print_time_tb function
518
- "Offset": integer representing number of lines of traceback information to be ignored (top down,
519
default is 1). This parameter is passed to the corresponding parameter of the
520
timeStampControl class and print_time_tb function.
521
- "ShowDateTime": boolean (Default = True). If set to False the date and time part of the message is supressed.
522
This parameter is passed to the corresponding parameter of the timeStampControl class and
523
print_time_tb function.
524
525
526
OUTPUT:
527
528
an instance of the class timeStampControl according to the given parameters
529
530
531
RAISE:
532
533
- ValueError "Elapse time must be non negative" if verbose is set to a negative integer
534
535
- TypeError "verbose mut be a boolean, integer, an instance of timeStampControll or a member of Enum TsLevel"
536
if verbose is something else (not allowed)
537
538
539
EXAMPLES:
540
541
verbose as boolean
542
543
sage: TestTimeStamp = setupTimeStamp( verbose = True )
544
sage: def testTsLevel( ):
545
....: TestTimeStamp.print_timestamp(Text="Entry", Level = TsLevel.StackInfo )
546
....: TestTimeStamp.print_timestamp(Text="Body", Level = TsLevel.Body )
547
....: TestTimeStamp.print_timestamp(Text="Exit", Level = TsLevel.StackInfo )
548
....:
549
sage: testTsLevel()
550
L: StackInfo Time 2016-10-11 08:39:16.355601 Elapse: 2001, Total: 2 Entry In: testTsLevel Line: 2
551
L: Body Time 2016-10-11 08:39:16.358169 Elapse: 3, Total: 2 Body In: testTsLevel Line: 3
552
L: StackInfo Time 2016-10-11 08:39:16.362389 Elapse: 2, Total: 2 Exit In: testTsLevel Line: 4
553
sage:
554
555
verbose as member of Enum "TsLevel":
556
557
sage: TestTimeStamp = setupTimeStamp( verbose = TsLevel.StackInfo )
558
sage: testTsLevel()
559
L: StackInfo Time 2016-10-11 08:38:03.463870 Elapse: 8481, Total: 8 Entry In: testTsLevel Line: 2
560
L: StackInfo Time 2016-10-11 08:38:03.466694 Elapse: 3, Total: 8 Exit In: testTsLevel Line: 4
561
sage:
562
563
verbose as instance of timeStampControl (resets Total Time Counter):
564
565
sage: TestTimeStamp = setupTimeStamp( verbose = TestTimeStamp )
566
sage: testTsLevel()
567
L: StackInfo Time 2016-10-11 18:20:39.091622 Elapse: 2302, Total: 2/ 81 Entry In: testTsLevel Line: 2
568
L: StackInfo Time 2016-10-11 18:20:39.094596 Elapse: 4, Total: 2/ 81 Exit In: testTsLevel Line: 4
569
sage: testTsLevel()
570
L: StackInfo Time 2016-10-11 18:20:44.686855 Elapse: 5592, Total: 7/ 86 Entry In: testTsLevel Line: 2
571
L: StackInfo Time 2016-10-11 18:20:44.689293 Elapse: 2, Total: 7/ 86 Exit In: testTsLevel Line: 4
572
573
default verbose = False:
574
575
sage: TestTimeStamp = setupTimeStamp( )
576
sage: testTsLevel()
577
578
verbose as integer (elapse time):
579
580
sage: TestTimeStamp = setupTimeStamp( verbose = 1 )
581
sage: testTsLevel()
582
L: StackInfo Time 2016-10-11 08:39:51.658389 Elapse: 1784, Total: 1 Entry In: testTsLevel Line: 2
583
---> <module> In: <ipython-input-18-85e0e9a26a0d> Line: 1
584
L: Body Time 2016-10-11 08:39:51.661864 Elapse: 4, Total: 1 Body In: testTsLevel Line: 3
585
---> <module> In: <ipython-input-18-85e0e9a26a0d> Line: 1
586
L: StackInfo Time 2016-10-11 08:39:51.665626 Elapse: 3, Total: 1 Exit In: testTsLevel Line: 4
587
---> <module> In: <ipython-input-18-85e0e9a26a0d> Line: 1
588
sage: TestTimeStamp = setupTimeStamp( verbose = 10 )
589
sage: testTsLevel()
590
L: StackInfo Time 2016-10-11 08:40:26.402257 Elapse: 1575, Total: 1 Entry In: testTsLevel Line: 2
591
---> <module> In: <ipython-input-20-85e0e9a26a0d> Line: 1
592
593
594
AUTHOR:
595
596
- Sebastian Oehms, Oct. 2016
597
598
"""
599
TimeStamp = None
600
LocTsLevel = TsLevel.Silent
601
elapsetime = _sage_const_0
602
603
if type( verbose ) == bool:
604
if verbose == True:
605
elapsetime = _sage_const_0
606
LocTsLevel = TsLevel.Debug
607
else:
608
elapsetime = _sage_const_0
609
LocTsLevel = TsLevel.Silent
610
elif type( verbose ) == Integer:
611
if verbose > _sage_const_0 :
612
elapsetime = verbose
613
LocTsLevel = TsLevel.Debug
614
else:
615
raise ValueError( "Elapse time must be non negative" )
616
elif isinstance( verbose, timeStampControl ) == True:
617
TimeStamp = verbose
618
elif isinstance( verbose, TsLevel ) == True:
619
LocTsLevel = verbose
620
else:
621
raise TypeError( "verbose mut be a boolean, integer, or an instance of %s or %s"\
622
%(timeStampControl, TsLevel ) )
623
624
if Offset == None:
625
Offset = _sage_const_1
626
627
if TraceBackDepth == None:
628
if elapsetime > _sage_const_0 :
629
# on elapsetime mode the default TraceBackDepth is 4
630
TraceBackDepth = _sage_const_4
631
else:
632
TraceBackDepth = _sage_const_1
633
634
if TimeStamp == None:
635
TimeStamp = timeStampControl( KeepSilentOnElapse = elapsetime, TimeStampLevel = LocTsLevel,
636
TraceBackDepth = TraceBackDepth, Offset = Offset, ShowDateTime = ShowDateTime )
637
else:
638
TimeStamp.reset()
639
640
return TimeStamp
641
642
643
644
645
646
647
648
649
650
651
652
def print_doc( function ):
653
"""
654
This function capsules a formatted print of the docstring
655
"""
656
print "\n"
657
print "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
658
print "-----------------------------------------------------------------------------------------------------------------"
659
print "Docstring of", function; print function.__doc__
660
print "_________________________________________________________________________________________________________________"
661
print "-----------------------------------------------------------------------------------------------------------------"
662
print "\n"
663
664
665
666