Das Modul slr (Das Modul slr), Lektion, Seite 724568
https://www.purl.org/stefan_ram/pub/slr_python (Permalink) ist die kanonische URI dieser Seite.
Stefan Ram

Das Modul »slr«

slr.py
"""
Stefan Ram's utilities module.

Version: 2020-02-02T01:11:29+01:00.

This module contains some utilties by Stefan Ram.

Mathematical Functions
----------------------

================== ==================================================
Function Description
================== ==================================================
sign the sign (signum) of the argument as -1, 0, or +1
================== ==================================================

Exceptions
----------

No exception is defined.
"""

import subprocess
import sys
import os.path
import inspect
import datetime
import os
import tempfile

def stamp():
return datetime.datetime.now().replace( microsecond=0 ).isoformat( 'T' )

def caller_name():
return inspect.currentframe().f_back.f_back.f_code.co_name

class default_context_class:
def __init__( __self__ ):
pass
def report( __self__, *s, **x ):
"""report, in a somewhat verbose manner, what is happening."""
print( ':'+ caller_name() + ' ' + stamp()+ ":report:", *s, **x )
def debug( __self__, *s, **x ):
print( ':'+ caller_name() + ' ' + stamp()+ ":debug:", *s, **x )
def error( __self__, *s, **x ):
print( ':'+ caller_name() + ' ' + stamp()+ ":error:", *s, **x )

default_context = default_context_class()

def mswin_execute_command( *args, context=default_context ):
print(args)
batch_file = tempfile.NamedTemporaryFile( 'wb', suffix='.cmd', delete=False, dir='.' )
batch_file.write( b"@chcp 65001 > nul\r\n" )
batch_file.write( b"@" )
command = subprocess.list2cmdline( args ).encode( "utf-8" )
batch_file.write( command )
batch_file.close()
try:
context.report( f'EXECUTING {command}' )
with subprocess.Popen \
( 'cmd.exe /c ' + batch_file.name,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT ) as p:
for line in p.stdout:
print( line.decode( 'utf-8' ), end='' )
context.report( 'returncode = ', p.returncode )
finally:
os.remove( batch_file.name )
return p.returncode

mswin_execute_command( "dir" )

def mswin_install_python_package( name ):
'''
e.g., pywin32
'''
mswin_execute_command( sys.executable, '-m', 'pip', 'install', name, '--force-reinstall' )

def execute_pywin32_postinstall(x):
"""# im scripts folder aufrufen:"""
execute_os_command( sys.executable, os.path.dirname(sys.executable)+r'\Scripts\pywin32_postinstall.py', '-install' )
print( 'You now need to restart your Python interpreter!' )

 

Seiteninformationen und Impressum   |   Mitteilungsformular  |   "ram@zedat.fu-berlin.de" (ohne die Anführungszeichen) ist die Netzpostadresse von Stefan Ram.   |   Eine Verbindung zur Stefan-Ram-Startseite befindet sich oben auf dieser Seite hinter dem Text "Stefan Ram".)  |   Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram. Schlüsselwörter zu dieser Seite/relevant keywords describing this page: Stefan Ram Berlin slrprd slrprd stefanramberlin spellched stefanram724568 stefan_ram:724568 Das Modul slr Stefan Ram, Berlin, and, or, near, uni, online, slrprd, slrprdqxx, slrprddoc, slrprd724568, slrprddef724568, PbclevtugFgrsnaEnz Erklärung, Beschreibung, Info, Information, Hinweis,

Der Urheber dieses Textes ist Stefan Ram. Alle Rechte sind vorbehalten. Diese Seite ist eine Veröffentlichung von Stefan Ram.
https://www.purl.org/stefan_ram/pub/slr_python