X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Futils.py;h=e5431c8bc63854337b0b0d9b518f58ff547bf2a5;hb=49c85ab8a723a425cc6539dd138dcd9e0913ab9f;hp=0d2f1fc6d2e7a52799cdcab6e8f4fd87b7010810;hpb=2ab14e9a096e43b846820363557183dab77a87b3;p=dak.git diff --git a/daklib/utils.py b/daklib/utils.py index 0d2f1fc6..e5431c8b 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -23,6 +23,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import commands +import datetime import email.Header import os import pwd @@ -608,6 +609,14 @@ def build_package_list(dsc, session = None): def send_mail (message, filename=""): """sendmail wrapper, takes _either_ a message string or a file as arguments""" + maildir = Cnf.get('Dir::Mail') + if maildir: + path = os.path.join(maildir, datetime.datetime.now().isoformat()) + path = find_next_free(path) + fh = open(path, 'w') + print >>fh, message, + fh.close() + # Check whether we're supposed to be sending mail if Cnf.has_key("Dinstall::Options::No-Mail") and Cnf["Dinstall::Options::No-Mail"]: return @@ -1586,3 +1595,25 @@ def mail_addresses_for_upload(maintainer, changed_by, fingerprint): encoded_addresses = [ fix_maintainer(e)[1] for e in addresses ] return encoded_addresses + +################################################################################ + +def call_editor(text="", suffix=".txt"): + """Run editor and return the result as a string + + Kwargs: + text (str): initial text + suffix (str): extension for temporary file + + Returns: + string with the edited text + """ + editor = os.environ.get('VISUAL', os.environ.get('EDITOR', 'vi')) + tmp = tempfile.NamedTemporaryFile(suffix=suffix, delete=False) + try: + print >>tmp, text, + tmp.close() + subprocess.check_call([editor, tmp.name]) + return open(tmp.name, 'r').read() + finally: + os.unlink(tmp.name)