Skip to content
GitLab
Explore
Sign in
archlinux
archversion
Compare revisions
1d91b08f7a409cd916c08cb5b4d50b13b205059c to 0cc6f62a35fc2c8619d951bda60f134109ddb04b
Commits on Source (4)
Raise error instead of exiting
· 93f5feb2
Seblu
authored
Nov 18, 2018
93f5feb2
Handle unknown and fatal execptions equally
· ad98138e
Seblu
authored
Nov 18, 2018
ad98138e
Support full tls mode and port config for sendmail
· 09282ac7
Seblu
authored
Nov 18, 2018
09282ac7
New package versioning
· 0cc6f62a
Seblu
authored
Nov 18, 2018
Fix commit count in pkgver Use date in pkgver
0cc6f62a
Show whitespace changes
Inline
Side-by-side
misc/PKGBUILD
View file @
0cc6f62a
# Maintainer: Sébastien Luttringer
# Maintainer: Sébastien Luttringer
pkgname
=
archversion-git
pkgname
=
archversion-git
pkgver
=
$(
git
log
--pretty
=
format:
''
|wc
-l
)
pkgver
=
$(
git
rev-list
--count
HEAD
)
pkgrel
=
1
pkgrel
=
$(
date
+%y%m%d
)
pkgdesc
=
'Archlinux Version Controller (Git version)'
pkgdesc
=
'Archlinux Version Controller (Git version)'
arch
=(
'any'
)
arch
=(
'any'
)
url
=
'https://github.com/seblu/archversion'
url
=
'https://github.com/seblu/archversion'
...
...
misc/sendmail.conf.example
View file @
0cc6f62a
[sendmail]
[sendmail]
# Options in this section are about sendmail command
#
M
ail address
#
To m
ail address
(mandatory)
# to = archversion@gmail.com
# to = archversion@gmail.com
# From mail address
# from = archversion@gmail.com
# default value is archversion
# Mail subject
# Mail subject
# subject = Archversion report
# subject = Archversion report
# default value is "Archversion report"
# SMTP server address (mandatory)
# host = smtp.honeypot.org
# SMTP server port
# port = 465
# default value is 25
# SMTP server
# SMTP server tls mode
# smtp = smtp.honeypot.org
# tls = no | starttls | yes
\ No newline at end of file
# default value is no
src/bin/archversion
View file @
0cc6f62a
...
@@ -23,14 +23,14 @@
...
@@ -23,14 +23,14 @@
from
archversion
import
VERSION
,
CONFIG_SENDMAIL
from
archversion
import
VERSION
,
CONFIG_SENDMAIL
from
archversion.config
import
BaseConfigFile
from
archversion.config
import
BaseConfigFile
from
archversion.error
import
BaseError
,
MissingConfigFile
,
NoSuchFile
from
archversion.error
import
BaseError
,
MissingConfigFile
,
NoSuchFile
from
archversion.error
import
ERR_FATAL
,
ERR_ABORT
,
ERR_UNKNOWN
from
archversion.error
import
ERR_FATAL
,
ERR_ABORT
from
archversion.pacman
import
parse_pkgbuild
,
pkgbuild_set_version
,
pkgbuild_update_checksums
from
archversion.pacman
import
parse_pkgbuild
,
pkgbuild_set_version
,
pkgbuild_update_checksums
from
archversion.version
import
VersionController
from
archversion.version
import
VersionController
from
email.mime.text
import
MIMEText
from
email.mime.text
import
MIMEText
from
email.utils
import
formatdate
from
email.utils
import
formatdate
from
io
import
StringIO
from
io
import
StringIO
from
pprint
import
pprint
from
pprint
import
pprint
from
smtplib
import
SMTP
from
smtplib
import
SMTP
,
SMTP_SSL
import
argparse
import
argparse
import
logging
import
logging
import
os
import
os
...
@@ -173,15 +173,19 @@ def command_sendmail(args, vctrl):
...
@@ -173,15 +173,19 @@ def command_sendmail(args, vctrl):
# check args
# check args
try
:
try
:
to
=
config
[
"
mail
"
][
"
to
"
]
to
=
config
[
"
mail
"
][
"
to
"
]
from_
=
config
[
"
mail
"
].
get
(
"
from
"
,
"
A
rchversion
<noreply@archlinux.org>
"
)
from_
=
config
[
"
mail
"
].
get
(
"
from
"
,
"
a
rchversion
"
)
subject
=
config
[
"
mail
"
].
get
(
"
subject
"
,
"
Archversion Report
"
)
subject
=
config
[
"
mail
"
].
get
(
"
subject
"
,
"
Archversion Report
"
)
smtp
=
config
[
"
smtp
"
][
"
host
"
]
host
=
config
[
"
smtp
"
][
"
host
"
]
port
=
config
[
"
smtp
"
].
get
(
"
port
"
,
"
25
"
)
login
=
config
[
"
smtp
"
].
get
(
"
login
"
)
login
=
config
[
"
smtp
"
].
get
(
"
login
"
)
password
=
config
[
"
smtp
"
].
get
(
"
password
"
)
password
=
config
[
"
smtp
"
].
get
(
"
password
"
)
start
tls
=
config
[
"
smtp
"
].
get
(
"
start
tls
"
,
"
false
"
).
lower
()
in
(
"
true
"
,
"
yes
"
)
tls
=
config
[
"
smtp
"
].
get
(
"
tls
"
,
"
no
"
).
lower
()
except
KeyError
as
exp
:
except
KeyError
as
exp
:
logging
.
error
(
"
Invalid sendmail config: %s
"
%
exp
)
raise
BaseError
(
"
Unable to load sendmail config
"
)
from
exp
exit
(
1
)
# check tls param
tls_values
=
(
"
yes
"
,
"
no
"
,
"
starttls
"
)
if
tls
not
in
tls_values
:
raise
BaseError
(
"
Invalid SMTP tls value: %s. Should be %s.
"
%
(
tls
,
"
|
"
.
join
(
tls_values
)))
# capture a report
# capture a report
stdout
=
StringIO
()
stdout
=
StringIO
()
stdout_bak
=
sys
.
stdout
stdout_bak
=
sys
.
stdout
...
@@ -199,16 +203,20 @@ def command_sendmail(args, vctrl):
...
@@ -199,16 +203,20 @@ def command_sendmail(args, vctrl):
msg
[
"
Date
"
]
=
formatdate
(
localtime
=
True
)
msg
[
"
Date
"
]
=
formatdate
(
localtime
=
True
)
# send the mail
# send the mail
try
:
try
:
s
=
SMTP
(
smtp
)
con
=
SMTP_SSL
()
if
tls
==
"
yes
"
else
SMTP
()
if
starttls
:
# since python3.7 we need to set host to establish ssl/tls connections
s
.
starttls
()
# this cannot be done in SMTP class contructor because it try to
# initiate the connection at that time
con
.
_host
=
host
con
.
connect
(
host
,
port
)
if
tls
==
"
starttls
"
:
con
.
starttls
()
if
login
:
if
login
:
s
.
login
(
login
,
password
)
con
.
login
(
login
,
password
)
s
.
send_message
(
msg
)
con
.
send_message
(
msg
)
s
.
quit
()
con
.
quit
()
except
Exception
as
exp
:
except
Exception
as
exp
:
logging
.
error
(
"
Sendmail fail: %s
"
%
exp
)
raise
BaseError
(
"
Unable to send mail
"
)
from
exp
exit
(
1
)
def
command_update
(
args
,
vctrl
):
def
command_update
(
args
,
vctrl
):
'''
Handle update command call
'''
'''
Handle update command call
'''
...
@@ -270,15 +278,11 @@ def main():
...
@@ -270,15 +278,11 @@ def main():
return
args
.
func
(
args
,
vctrl
)
return
args
.
func
(
args
,
vctrl
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
exit
(
ERR_ABORT
)
exit
(
ERR_ABORT
)
except
BaseError
as
exp
:
logging
.
error
(
exp
)
exit
(
ERR_FATAL
)
except
Exception
as
exp
:
except
Exception
as
exp
:
logging
.
error
(
"
Unknown error. Please report it with --debug.
"
)
logging
.
critical
(
exp
)
logging
.
error
(
exp
)
if
logging
.
getLogger
().
getEffectiveLevel
()
==
logging
.
DEBUG
:
if
logging
.
getLogger
().
getEffectiveLevel
()
==
logging
.
DEBUG
:
raise
raise
exit
(
ERR_
UNKNOWN
)
exit
(
ERR_
FATAL
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
main
()
main
()
...
...
src/lib/archversion/error.py
View file @
0cc6f62a
...
@@ -24,7 +24,6 @@ import logging
...
@@ -24,7 +24,6 @@ import logging
ERR_USAGE
=
1
ERR_USAGE
=
1
ERR_FATAL
=
2
ERR_FATAL
=
2
ERR_ABORT
=
3
ERR_ABORT
=
3
ERR_UNKNOWN
=
4
class
BaseError
(
Exception
):
class
BaseError
(
Exception
):
'''
First ancenstor of errors
'''
'''
First ancenstor of errors
'''
...
...