annotate scripts/spam-remover @ 8566:e4191aa7b402 default tip

doc: issue2551415 correct doc for change input->input_payload in 2.5 the rest interface changed a variable name from input to input_payload. An earlier commit changed the rest docs. This commit adds an item for it to the upgrading 2.4.0->2.5.0 section. Also cross reference added to the rest docs with the updated examples.
author John Rouillard <rouilj@ieee.org>
date Thu, 09 Apr 2026 00:19:06 -0400
parents 9c3ec0a5c7fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
1 #! /usr/bin/env python
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
2 # Copyright (C) 2012 Dr. Ralf Schlatterbeck Open Source Consulting.
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
3 # Reichergasse 131, A-3411 Weidling.
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
4 # Web: http://www.runtux.com Email: rsc@runtux.com
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
5 # All rights reserved
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
6 #
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
8 # of this software and associated documentation files (the "Software"), to deal
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
9 # in the Software without restriction, including without limitation the rights
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
11 # copies of the Software, and to permit persons to whom the Software is
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
12 # furnished to do so, subject to the following conditions:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
13 #
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
14 # The above copyright notice and this permission notice shall be included in
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
15 # all copies or substantial portions of the Software.
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
16 #
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
23 # SOFTWARE.
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
24
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
25 _doc = '''
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
26 %prog [options]
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
27 Remove file attachment spam from a tracker:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
28 - Edit the journal of the given issue(s) and remove the links to the
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
29 spam-files
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
30 - Set the contents of the spam-files involved to zero length
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
31 WARNING:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
32 This is a dangerous operation as it will edit the history *and* remove
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
33 data that is not in the journal (the contents of files). Be careful with
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
34 the file pattern (start of filename) you specify!
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
35 '''
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
36
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
37 import sys
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
38 from optparse import OptionParser
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
39 from roundup import instance, hyperdb
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
40
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
41 def main():
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
42 cmd = OptionParser(usage=_doc)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
43 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
44 ( "-i", "--instance"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
45 , help = "Instance home"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
46 , default = "."
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
47 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
48 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
49 ( "-d", "--designator"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
50 , dest = "designators"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
51 , help = "Item designator for issue(s), to remove files from,\n"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
52 "e.g. issue4711"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
53 , action = "append"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
54 , default = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
55 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
56 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
57 ( "-f", "--filename"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
58 , dest = "filenames"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
59 , help = "Exact spam-filename to remove from issue(s)"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
60 , action = "append"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
61 , default = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
62 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
63 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
64 ( "-a", "--action", "--no-dry-run"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
65 , dest = "doit"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
66 , help = "Don't perform any action by default unless specified"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
67 , action = "store_true"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
68 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
69 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
70 ( "-s", "--file-start-pattern"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
71 , dest = "file_pattern"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
72 , help = "Start of spam-filename to remove from issue(s)"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
73 , action = "append"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
74 , default = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
75 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
76 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
77 ( "-u", "--spam-user"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
78 , dest = "users"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
79 , help = "Username that created the spam-files to remove"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
80 , action = "append"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
81 , default = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
82 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
83 cmd.add_option \
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
84 ( "-q", "--quiet"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
85 , dest = "quiet"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
86 , help = "Be quiet about what we're doing"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
87 , action = "store_true"
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
88 )
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
89 opt, args = cmd.parse_args()
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
90 # open the instance
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
91 if len(args):
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
92 print("This command doesn't take arguments", file=sys.stderr)
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
93 cmd.show_help()
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
94 tracker = instance.open(opt.instance)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
95 db = tracker.open('admin')
4781
6e9b9743de89 Implementation for:
John Rouillard <rouilj@ieee.org>
parents: 4667
diff changeset
96 db.tx_Source = "cli"
6e9b9743de89 Implementation for:
John Rouillard <rouilj@ieee.org>
parents: 4667
diff changeset
97
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
98 users = dict.fromkeys (db.user.lookup(u) for u in opt.users)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
99 files_to_remove = {}
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
100 for fn in opt.filenames:
4661
73129d1a1bc3 Fix file options for spam-remover script, set content to single space.
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4660
diff changeset
101 for fid in db.file.filter(None,dict(name=fn)):
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
102 if db.file.get(fid,'name') == fn:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
103 files_to_remove[fid] = True
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
104 for fn in opt.file_pattern:
4661
73129d1a1bc3 Fix file options for spam-remover script, set content to single space.
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4660
diff changeset
105 for fid in db.file.filter(None,dict(name=fn)):
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
106 if db.file.get(fid,'name').startswith(fn):
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
107 files_to_remove[fid] = True
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
108 files_found = {}
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
109 for d in opt.designators:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
110 clsname, id = hyperdb.splitDesignator(d)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
111 cls = db.getclass(clsname)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
112 issuefiles = dict.fromkeys(cls.get (id, 'files'))
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
113 for fid in list(issuefiles.keys()):
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
114 f = db.file.getnode(fid)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
115 if fid in files_to_remove or f.creator in users:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
116 files_to_remove[fid] = True
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
117 files_found[fid] = True
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
118 if not opt.quiet:
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
119 print("deleting file %s from issue" % f)
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
120 del issuefiles[fid]
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
121 if opt.doit:
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
122 cls.set(id, files=list(issuefiles.keys()))
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
123 journal = oldjournal = db.getjournal(clsname, id)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
124 # do this twice, we may have file-removals *before* file
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
125 # additions for files to delete and may discover mid-journal
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
126 # that there are new files to remove
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
127 for x in range(2):
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
128 newjournal = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
129 for j in journal:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
130 if j[3] == 'set' and 'files' in j[4]:
4667
f841a5868101 Bug-fix in spam-remover script: ignore cases where file-list is set
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4661
diff changeset
131 if j[4]['files'][0][0] not in ('-', '+') :
f841a5868101 Bug-fix in spam-remover script: ignore cases where file-list is set
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4661
diff changeset
132 newjournal.append(j)
f841a5868101 Bug-fix in spam-remover script: ignore cases where file-list is set
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4661
diff changeset
133 continue
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
134 changes = dict(j[4]['files'])
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
135 # only consider file additions by this user
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
136 if j[2] in users and '+' in changes:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
137 f = dict.fromkeys(changes['+'])
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
138 files_found.update(f)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
139 files_to_remove.update(f)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
140 del changes['+']
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
141 # change dict in-place
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
142 for k, v in list(changes.items()):
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
143 new_f = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
144 for f in v:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
145 if f in files_to_remove:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
146 files_found[f] = True
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
147 else:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
148 new_f.append(f)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
149 if new_f :
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
150 changes[k] = new_f
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
151 else:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
152 del changes[k]
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
153 msg = []
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
154 if not opt.quiet:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
155 msg.append ("Old journal entry: %s" % str(j))
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
156 if changes:
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
157 j[4]['files'] = tuple(changes.items())
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
158 else:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
159 del j[4]['files']
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
160 if j[4]:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
161 newjournal.append(j)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
162 if not opt.quiet:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
163 msg.append ("New journal entry: %s" % str(j))
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
164 elif not opt.quiet:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
165 msg.append ("deleted")
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
166 if len(msg) == 2 and msg[0][4:] != msg[1][4:]:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
167 for m in msg:
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
168 print(m)
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
169 else:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
170 newjournal.append(j)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
171 journal = newjournal
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
172 if newjournal != oldjournal and opt.doit:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
173 db.setjournal(clsname, id, newjournal)
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
174 if opt.doit:
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
175 for f in files_found:
4661
73129d1a1bc3 Fix file options for spam-remover script, set content to single space.
Ralf Schlatterbeck <rsc@runtux.com>
parents: 4660
diff changeset
176 db.file.set(f, content=' ')
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
177 db.commit()
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
178 else:
5412
c75defc1c2f0 Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents: 4781
diff changeset
179 print("Database not changed")
4660
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
180
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
181
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
182 if __name__ == '__main__':
9f507a042c1b Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff changeset
183 main()

Roundup Issue Tracker: http://roundup-tracker.org/