28
28
from debian.changelog import Version
29
from devscripts.logger import Logger
29
30
from distro_info import DebianDistroInfo
31
32
from ubuntutools.archive import rmadison, FakeSPPH
114
115
# prepare sign command
115
116
gpg_command = None
116
for cmd in ('gpg', 'gpg2', 'gnome-gpg'):
117
for cmd in ('gnome-gpg', 'gpg2', 'gpg'):
117
118
if os.access('/usr/bin/%s' % cmd, os.X_OK):
118
119
gpg_command = [cmd]
119
assert gpg_command # TODO: catch exception and produce error message
123
Logger.error("Cannot locate gpg, please install the 'gnupg' package")
121
126
gpg_command.append('--clearsign')
126
131
gpg = subprocess.Popen(gpg_command, stdin=subprocess.PIPE,
127
132
stdout=subprocess.PIPE)
128
133
signed_report = gpg.communicate(mailbody.encode('utf-8'))[0].decode('utf-8')
129
assert gpg.returncode == 0
134
if gpg.returncode != 0:
135
Logger.error("%s failed", gpg_command[0])
143
150
# connect to the server
145
print 'Connecting to %s:%s ...' % (mailserver_host, mailserver_port)
152
Logger.info('Connecting to %s:%s ...', mailserver_host, mailserver_port)
146
153
s = smtplib.SMTP(mailserver_host, mailserver_port)
147
154
except socket.error, s:
148
print >> sys.stderr, 'E: Could not connect to %s:%s: %s (%i)' % \
149
(mailserver_host, mailserver_port, s[1], s[0])
155
Logger.error('Could not connect to %s:%s: %s (%i)',
156
mailserver_host, mailserver_port, s[1], s[0])
152
159
if mailserver_user and mailserver_pass:
154
161
s.login(mailserver_user, mailserver_pass)
155
162
except smtplib.SMTPAuthenticationError:
156
print >> sys.stderr, ('E: Error authenticating to the server: '
157
'invalid username and password.')
163
Logger.error('Error authenticating to the server: '
164
'invalid username and password.')
161
print >> sys.stderr, 'E: Unknown SMTP error.'
168
Logger.error('Unknown SMTP error.')
165
172
s.sendmail(myemailaddr, to, mail.encode('utf-8'))
167
print 'Sync request mailed.'
174
Logger.normal('Sync request mailed.')