~james-w/bzr-builder/trunk-old

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: James Westby
  • Date: 2009-09-21 18:07:53 UTC
  • mfrom: (48.1.3 bzr-builder)
  • Revision ID: james.westby@canonical.com-20090921180753-p1sb79l0524iea6c
Use the same algorithm as dch to get changelog name and email.

Stop hard-coding my email address. Thanks Javier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
import datetime
127
127
from email import utils
128
128
import os
 
129
import pwd
 
130
import re
 
131
import socket
129
132
import shutil
130
133
import subprocess
131
134
import tempfile
327
330
                        "specified.")
328
331
            if distribution is None:
329
332
                distribution = "jaunty"
330
 
        # FIXME: should pick this up from the environment in the same way
331
 
        # as dch. (Should probably be in python-debian)
332
 
        author = "bzr-builder <jamesw@ubuntu.com>"
 
333
        # Use debian packaging environment variables
 
334
        # or default values if they don't exist
 
335
        author = "%s <%s>" % self._get_maintainer()
 
336
 
333
337
        date = utils.formatdate(localtime=True)
334
338
        cl.new_block(package=package, version=base_branch.deb_version,
335
339
                distributions=distribution, urgency="low",
341
345
        finally:
342
346
            cl_f.close()
343
347
 
 
348
 
 
349
    def _get_maintainer(self):
 
350
        """
 
351
        Create maintainer string using the same algorithm as in dch
 
352
        """
 
353
        env = os.environ
 
354
        regex = re.compile(r"^(.*)\s+<(.*)>$")
 
355
 
 
356
        # Split email and name
 
357
        if 'DEBEMAIL' in env:
 
358
            match_obj = regex.match(env['DEBEMAIL'])
 
359
            if match_obj:
 
360
                if not 'DEBFULLNAME' in env:
 
361
                    env['DEBFULLNAME'] = match_obj.group(1)
 
362
                env['DEBEMAIL'] = match_obj.group(2)
 
363
        if 'DEBEMAIL' not in env or 'DEBFULLNAME' not in env:
 
364
            if 'EMAIL' in env:
 
365
                match_obj = regex.match(env('EMAIL'))
 
366
                if match_obj:
 
367
                    if not 'DEBFULLNAME' in env:
 
368
                        env['DEBFULLNAME'] = match_obj.group(1)
 
369
                    env['EMAIL'] = match_obj.group(2)
 
370
 
 
371
        # Get maintainer's name
 
372
        if 'DEBFULLNAME' in env:
 
373
            maintainer = env['DEBFULLNAME']
 
374
        elif 'NAME' in env:
 
375
            maintainer = env['NAME']
 
376
        else:
 
377
            # Use password database if no data in environment variables
 
378
            try:
 
379
                maintainer = re.sub(r',.*', '', pwd.getpwuid(os.getuid()).pw_gecos)
 
380
            except KeyError, AttributeError:
 
381
                # TBD: Use last changelog entry value
 
382
                maintainer = "bzr-builder"
 
383
 
 
384
        # Get maintainer's mail address
 
385
        if 'DEBEMAIL' in env:
 
386
            email = env['DEBEMAIL']
 
387
        elif 'MAIL' in env:
 
388
            email = env['MAIL']
 
389
        else:
 
390
            addr = None
 
391
            if os.path.exists('/etc/mailname'):
 
392
                f = open('/etc/mailname')
 
393
                try:
 
394
                    addr = f.readline().strip()
 
395
                finally:
 
396
                    f.close()
 
397
            if not addr:
 
398
                addr = socket.getfqdn()
 
399
            if addr:
 
400
                user = pwd.getpwuid(os.getuid()).pw_name
 
401
                if not user:
 
402
                    addr = None
 
403
                else:
 
404
                    addr = "%s@%s" % (user, addr)
 
405
 
 
406
            if addr:
 
407
                email = addr
 
408
            else:
 
409
                # TBD: Use last changelog entry value
 
410
                email = "none@example.org"
 
411
 
 
412
        return (maintainer, email)
 
413
 
 
414
 
344
415
    def _build_source_package(self, basedir):
345
416
        trace.note("Building the source package")
346
417
        command = ["/usr/bin/debuild", "--no-tgz-check", "-i", "-I", "-S",