Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
tracremind
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefy Lanza (nextime / spora )
tracremind
Commits
f7ec86ea
Commit
f7ec86ea
authored
May 01, 2015
by
nextime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
163 additions
and
0 deletions
+163
-0
tracremind.conf
tracremind.conf
+8
-0
tracremind.py
tracremind.py
+155
-0
No files found.
tracremind.conf
0 → 100644
View file @
f7ec86ea
[
DEFAULT
]
project
: /
path
/
to
/
trac
/
env
/
sendto
:
email
@
tosend
.
tld
[
projectname
]
project
: /
path
/
to
/
trac
/
env
/
projectname
sendto
:
email
@
tosend
.
tld
,
other_email
@
tosend
.
tld
,
other_address
@
tosend
.
tld
tracremind.py
0 → 100755
View file @
f7ec86ea
#!/usr/bin/env python
import
os
import
sys
import
string
import
getopt
import
ConfigParser
import
smtplib
from
email.MIMEText
import
MIMEText
import
time
class
TicketReminder
(
object
):
env
=
None
def
__init__
(
self
,
env
,
parameters
):
self
.
env
=
env
self
.
db
=
None
self
.
recipients
=
[]
def
start
(
self
):
self
.
db
=
self
.
env
.
get_db_cnx
()
cursor
=
self
.
db
.
cursor
()
sql
=
"select time,summary,owner,id from ticket where status = 'new' order by time DESC;"
cursor
.
execute
(
sql
)
ntickets
=
cursor
.
fetchall
()
sql
=
"""select time,summary,owner,status,id from ticket where status != 'new'
and status != 'closed' order by time DESC;"""
cursor
.
execute
(
sql
)
otickets
=
cursor
.
fetchall
()
msg
=
"Report open Tickets on Trac "
+
self
.
env
.
project_name
+
":
\n\n
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\n\n
"
msg
=
msg
+
"New tickets:
\n\n
"
for
nt
in
ntickets
:
msg
=
msg
+
"Date: "
+
self
.
ts2date
(
nt
[
0
])
+
"
\n
"
msg
=
msg
+
"Summary: "
+
nt
[
1
]
+
"
\n
"
if
nt
[
2
]
!=
None
:
msg
=
msg
+
"Owner: "
+
nt
[
2
]
+
"
\n
"
msg
=
msg
+
"Url: "
+
self
.
env
.
project_url
+
"ticket/"
+
str
(
nt
[
3
])
+
"
\n
"
msg
=
msg
+
"------------------------------
\n
"
msg
=
msg
+
"
\n\n
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\n\n
"
msg
=
msg
+
"Active Tickets:
\n\n
"
for
ot
in
otickets
:
msg
=
msg
+
"Date: "
+
self
.
ts2date
(
ot
[
0
])
+
"
\n
"
msg
=
msg
+
"Summary: "
+
ot
[
1
]
+
"
\n
"
if
ot
[
2
]
!=
None
:
msg
=
msg
+
"Owner: "
+
ot
[
2
]
+
"
\n
"
msg
=
msg
+
"State: "
+
ot
[
3
]
+
"
\n
"
msg
=
msg
+
"Url: "
+
self
.
env
.
project_url
+
"ticket/"
+
str
(
ot
[
4
])
+
"
\n
"
msg
=
msg
+
"------------------------------
\n
"
mailmsg
=
MIMEText
(
msg
)
mailmsg
[
'Subject'
]
=
"Report open Tickets on Trac "
+
self
.
env
.
project_name
+
" "
+
self
.
ts2date
(
time
.
time
())
mailmsg
[
'From'
]
=
'advisor@trac.nexlab.it'
mailmsg
[
'To'
]
=
settings
[
'sendto'
]
.
split
(
','
)[
0
]
cc
=
None
for
addr
in
settings
[
'sendto'
]
.
split
(
','
)[
1
:]:
if
cc
==
None
:
cc
=
addr
.
replace
(
" "
,
""
)
else
:
cc
=
cc
+
","
+
addr
.
replace
(
" "
,
""
)
if
cc
:
mailmsg
[
'Cc'
]
=
cc
s
=
smtplib
.
SMTP
()
s
.
connect
()
s
.
sendmail
(
mailmsg
[
'From'
],
mailmsg
[
'To'
],
mailmsg
.
as_string
())
s
.
close
()
def
ts2date
(
self
,
ts
):
return
time
.
strftime
(
'
%
d-
%
m-
%
y
%
H:
%
M'
,
time
.
localtime
(
ts
))
def
ReadConfig
(
name
,
config
):
"""
Parse the config file
"""
# Use given project name else use defaults
#
if
name
:
if
not
config
.
has_section
(
name
):
print
"Not a valid project name:
%
s"
%
name
print
"Valid names:
%
s"
%
config
.
sections
()
sys
.
exit
(
1
)
project
=
dict
()
for
option
in
config
.
options
(
name
):
project
[
option
]
=
config
.
get
(
name
,
option
)
else
:
project
=
config
.
defaults
()
return
project
def
GetConfigSections
(
file
):
if
not
os
.
path
.
isfile
(
file
):
print
'File
%
s does not exist'
%
file
sys
.
exit
(
1
)
config
=
ConfigParser
.
ConfigParser
()
try
:
config
.
read
(
file
)
except
ConfigParser
.
MissingSectionHeaderError
,
detail
:
print
detail
sys
.
exit
(
1
)
return
[
config
,
config
.
sections
()]
if
__name__
==
'__main__'
:
# Default config file
#
configfile
=
'/etc/tracremind.conf'
project
=
''
component
=
''
ENABLE_SYSLOG
=
0
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'f:p:'
,
[
'file='
,
'project='
])
except
getopt
.
error
,
detail
:
print
__doc__
print
detail
sys
.
exit
(
1
)
projects_name
=
[]
for
opt
,
value
in
opts
:
if
opt
in
[
'-f'
,
'--file'
]:
configfile
=
value
elif
opt
in
[
'-p'
,
'--project'
]:
projects_name
=
[
value
]
if
len
(
projects_name
)
==
0
:
projects_name
=
[
None
]
config
,
allprojects
=
GetConfigSections
(
configfile
)
if
projects_name
[
0
]
==
'all'
:
projects_name
=
allprojects
for
pname
in
projects_name
:
settings
=
ReadConfig
(
pname
,
config
)
if
not
settings
.
has_key
(
'project'
):
print
__doc__
print
'No Trac project is defined in the tracremind config file.'
sys
.
exit
(
1
)
print
pname
try
:
from
trac.env
import
Environment
from
trac.ticket
import
Ticket
from
trac.web.href
import
Href
from
trac
import
util
env
=
Environment
(
settings
[
'project'
],
create
=
0
)
tktremind
=
TicketReminder
(
env
,
settings
)
tktremind
.
start
()
except
:
sys
.
exit
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment