[Python-de] Re: Funktion ueberschreiben?

Mike Müller <mmueller-Nw5JoyH4ZXncp1/[email protected]>
Newsgroups gmane.comp.python.general.german
Organization Python Academy GmbH & Co. KG
Message-ID <[email protected]>
Am 03.12.22 um 09:28 schrieb Ulli Horlacher:
> Ich teste gerade duply/duplicity.
> U.a. stoert mich da Ausgabe des Datums in US Format, zB:
> 
> Last full backup date: Tue Nov 29 17:38:31 2022
> Fri Dec  2 09:08:31 2022 .
> 
> Ich hab auch schon die Stelle gefunden, wo das passiert:
> 
> /usr/lib/python3/dist-packages/duplicity/dup_time.py
> 
> def timetopretty(timeinseconds):
>      u"""Return pretty version of time"""
>      return time.asctime(time.localtime(timeinseconds))
>      
>      
> Ist also hard coded und nicht User konfigurierbar.
> 
> Ich hab nun die letzte Zeile ersetzt durch:
> 
>      return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timeinseconds))
> 
> 
> Damit bekomme ich brauchbares ISO Datumsformat:
> 
> Last full backup date: 2022-11-29 17:38:31
> 2022-12-02 09:08:31 .
> 
> ABER: duplicity ist ein Ubuntu-Paket und beim naechstes (automatischen)
> Update wird mein modifiziertes dup_time.py ersetzt.
> Irgendwelche Aenderungen des Original-Codes verbieten sich also.
> 
> Meine Idee nun:
> 
> Ich schreibe einen wrapper fuer duplicity, der time.asctime() durch meine
> obige Funktion ersetzt. So wuerde ich das zumindest bei C oder Perl machen.
> 
> (Wie) geht das bei Python?

import duplicity.dup_time

def timetopretty(timeinseconds):
     """Return pretty version of time"""
     return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(timeinseconds))

duplicity.dup_time.timetopretty = timetopretty

ganz zu Beginn des Programms sollte funktionieren. Wichtig ist, dass
duplicity.dup_time nicht schon vorher importiert wird. Sonst müsstest du es
vorher aus sys.modules entfernen.

Viele Grüße
Mike
_______________________________________________
python-de Mailingliste -- [email protected]
Zur Abmeldung von dieser Mailingliste senden Sie eine Nachricht an [email protected]
https://mail.python.org/mailman3/lists/python-de.python.org/
Mitgliedsadresse: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.