[gestion] darcs_send_changes pour darcs2
darcs-hash:20100117203137-ffbb2-370342287f729be92531915a88580d24587eb443.gz
This commit is contained in:
parent
355d052b27
commit
a8e2272d94
1 changed files with 55 additions and 14 deletions
|
@ -5,7 +5,7 @@
|
||||||
# ---------------------
|
# ---------------------
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Jeremie Dimino <jeremie@dimino.org>
|
# Copyright (C) 2007 Jeremie Dimino <jeremie@dimino.org>
|
||||||
# Copyright (C) 2007,2008 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
# Copyright (C) 2007,2008,2010 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
|
||||||
#
|
#
|
||||||
# This file is free software; you can redistribute it and/or modify
|
# 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
|
# 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.
|
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:
|
try:
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
@ -50,6 +55,7 @@ from email import Encoders
|
||||||
CONF_PATH = "_darcs/third-party/darcs-send-changes"
|
CONF_PATH = "_darcs/third-party/darcs-send-changes"
|
||||||
DATE_FILE = CONF_PATH + "/date-last-send"
|
DATE_FILE = CONF_PATH + "/date-last-send"
|
||||||
ID_FILE = CONF_PATH + "/id"
|
ID_FILE = CONF_PATH + "/id"
|
||||||
|
DARCS2 = False
|
||||||
|
|
||||||
def to_utf8(input):
|
def to_utf8(input):
|
||||||
""" Decode un str ou un unicode vers un str en UTF-8. """
|
""" Decode un str ou un unicode vers un str en UTF-8. """
|
||||||
|
@ -70,16 +76,32 @@ def to_utf8(input):
|
||||||
except (UnicodeDecodeError, UnicodeEncodeError):
|
except (UnicodeDecodeError, UnicodeEncodeError):
|
||||||
return input.decode("ascii", "replace").encode("UTF-8")
|
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):
|
def darcs(args):
|
||||||
""" Invoque darcs et renvoie sa sortie. """
|
""" Invoque darcs et renvoie sa sortie. """
|
||||||
(s, o) = commands.getstatusoutput("env DARCS_DONT_ESCAPE_8BIT=1 darcs " + args)
|
(s, o) = commands.getstatusoutput("env DARCS_DONT_ESCAPE_8BIT=1 darcs " + args)
|
||||||
o = to_utf8(o)
|
o = to_utf8(o)
|
||||||
return (s, 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. """
|
""" Récupère les informations a propos d'un certain patch. """
|
||||||
if hash:
|
if patch:
|
||||||
match_cmd = "--match='hash %s'" % hash
|
date = getdate(patch)
|
||||||
|
match_cmd = "--match='date %s'" % date
|
||||||
else:
|
else:
|
||||||
match_cmd = "--last 1"
|
match_cmd = "--last 1"
|
||||||
(status, changelog) = darcs("changes %s --xml-output" % match_cmd)
|
(status, changelog) = darcs("changes %s --xml-output" % match_cmd)
|
||||||
|
@ -202,19 +224,34 @@ def getnew(lastdate=None):
|
||||||
lastdate='19700101000000'
|
lastdate='19700101000000'
|
||||||
files = os.listdir("_darcs/patches")
|
files = os.listdir("_darcs/patches")
|
||||||
patches = []
|
patches = []
|
||||||
for f in files:
|
if not DARCS2:
|
||||||
if f.endswith(".gz"):
|
for f in files:
|
||||||
date = f.split("-", 1)[0]
|
if f.endswith(".gz"):
|
||||||
if date > lastdate:
|
date = getdate(f)
|
||||||
patches.append(f)
|
if date > lastdate:
|
||||||
patches.sort()
|
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
|
return patches
|
||||||
|
|
||||||
def select(patches):
|
def select(patches):
|
||||||
'''Sélection interactive de patches'''
|
'''Sélection interactive de patches'''
|
||||||
decided = []
|
decided = []
|
||||||
while patches:
|
while patches:
|
||||||
(status, changelog) = darcs("changes --match='hash %s'" % patches[0])
|
(status, changelog) = darcs("changes --match='date %s'" % getdate(patches[0]))
|
||||||
if status == 0:
|
if status == 0:
|
||||||
print
|
print
|
||||||
print changelog
|
print changelog
|
||||||
|
@ -298,6 +335,10 @@ if __name__ == "__main__":
|
||||||
cprint("Pas de dépôt darcs trouvé")
|
cprint("Pas de dépôt darcs trouvé")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
DARCS2 = "darcs-2" in open('_darcs/format').read()
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
|
||||||
if not os.path.exists(CONF_PATH):
|
if not os.path.exists(CONF_PATH):
|
||||||
partial_path = ''
|
partial_path = ''
|
||||||
|
@ -322,7 +363,7 @@ if __name__ == "__main__":
|
||||||
patches = getnew(lastdate)
|
patches = getnew(lastdate)
|
||||||
if c == "none":
|
if c == "none":
|
||||||
if patches:
|
if patches:
|
||||||
open(DATE_FILE, "w").write(patches[-1].split("-", 1)[0])
|
open(DATE_FILE, "w").write(getdate(patches[-1]))
|
||||||
patches = []
|
patches = []
|
||||||
else:
|
else:
|
||||||
open(DATE_FILE, "w").write("19700101000000")
|
open(DATE_FILE, "w").write("19700101000000")
|
||||||
|
@ -352,4 +393,4 @@ if __name__ == "__main__":
|
||||||
if props:
|
if props:
|
||||||
cprint("Envoi du patch %s a %s." % (props['hash'], ", ".join(recipient)))
|
cprint("Envoi du patch %s a %s." % (props['hash'], ", ".join(recipient)))
|
||||||
send_changes(smtplib.SMTP(smtp), recipient, props)
|
send_changes(smtplib.SMTP(smtp), recipient, props)
|
||||||
open(DATE_FILE, "w").write(patch.split("-", 1)[0])
|
open(DATE_FILE, "w").write(getdate(patch))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue