From a8e2272d94c190fa51f98ec9f7a188c5ee383a01 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Sun, 17 Jan 2010 21:31:37 +0100 Subject: [PATCH] [gestion] darcs_send_changes pour darcs2 darcs-hash:20100117203137-ffbb2-370342287f729be92531915a88580d24587eb443.gz --- gestion/darcs_send_changes.py | 69 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/gestion/darcs_send_changes.py b/gestion/darcs_send_changes.py index e7264f34..fa0f5efb 100644 --- a/gestion/darcs_send_changes.py +++ b/gestion/darcs_send_changes.py @@ -5,7 +5,7 @@ # --------------------- # # Copyright (C) 2007 Jeremie Dimino -# Copyright (C) 2007,2008 Nicolas Dandrimont +# Copyright (C) 2007,2008,2010 Nicolas Dandrimont # # This file is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -26,7 +26,12 @@ Envoie un mail détaillant le dernier patch appliqué à un dépot. """ -import commands, os, sys, email +import commands +import email +import gzip +import os +import sys +import time try: from lxml import etree @@ -50,6 +55,7 @@ from email import Encoders CONF_PATH = "_darcs/third-party/darcs-send-changes" DATE_FILE = CONF_PATH + "/date-last-send" ID_FILE = CONF_PATH + "/id" +DARCS2 = False def to_utf8(input): """ Decode un str ou un unicode vers un str en UTF-8. """ @@ -70,16 +76,32 @@ def to_utf8(input): except (UnicodeDecodeError, UnicodeEncodeError): return input.decode("ascii", "replace").encode("UTF-8") +def getdate(patch): + """Récupère la date correspondant à un patch...""" + if not DARCS2: + return patch.split("-", 1)[0] + else: + f = os.path.join("_darcs/patches", patch) + gzf = gzip.open(f) + try: + g = gzf.readlines() + except IOError: + gzf.close() + return '19700101000000' + gzf.close() + return g[1].split("**")[1] + def darcs(args): """ Invoque darcs et renvoie sa sortie. """ (s, o) = commands.getstatusoutput("env DARCS_DONT_ESCAPE_8BIT=1 darcs " + args) o = to_utf8(o) return (s, o) -def get_patch_properties(hash): +def get_patch_properties(patch): """ Récupère les informations a propos d'un certain patch. """ - if hash: - match_cmd = "--match='hash %s'" % hash + if patch: + date = getdate(patch) + match_cmd = "--match='date %s'" % date else: match_cmd = "--last 1" (status, changelog) = darcs("changes %s --xml-output" % match_cmd) @@ -202,19 +224,34 @@ def getnew(lastdate=None): lastdate='19700101000000' files = os.listdir("_darcs/patches") patches = [] - for f in files: - if f.endswith(".gz"): - date = f.split("-", 1)[0] - if date > lastdate: - patches.append(f) - patches.sort() + if not DARCS2: + for f in files: + if f.endswith(".gz"): + date = getdate(f) + if date > lastdate: + patches.append(f) + patches.sort() + else: + for f in files: + if getdate(f) > lastdate: + gz = gzip.open(os.path.join('_darcs/patches',f)) + try: + gz.read(1) + except IOError: + gz.close() + continue + else: + patches.append((getdate(f), f)) + patches.sort() + patches = [patch for _, patch in patches] + return patches def select(patches): '''Sélection interactive de patches''' decided = [] while patches: - (status, changelog) = darcs("changes --match='hash %s'" % patches[0]) + (status, changelog) = darcs("changes --match='date %s'" % getdate(patches[0])) if status == 0: print print changelog @@ -298,6 +335,10 @@ if __name__ == "__main__": cprint("Pas de dépôt darcs trouvé") sys.exit(1) + try: + DARCS2 = "darcs-2" in open('_darcs/format').read() + except IOError: + pass if not os.path.exists(CONF_PATH): partial_path = '' @@ -322,7 +363,7 @@ if __name__ == "__main__": patches = getnew(lastdate) if c == "none": if patches: - open(DATE_FILE, "w").write(patches[-1].split("-", 1)[0]) + open(DATE_FILE, "w").write(getdate(patches[-1])) patches = [] else: open(DATE_FILE, "w").write("19700101000000") @@ -352,4 +393,4 @@ if __name__ == "__main__": if props: cprint("Envoi du patch %s a %s." % (props['hash'], ", ".join(recipient))) send_changes(smtplib.SMTP(smtp), recipient, props) - open(DATE_FILE, "w").write(patch.split("-", 1)[0]) + open(DATE_FILE, "w").write(getdate(patch))