Mercurial > p > roundup > code
annotate scripts/spam-remover @ 7932:55229bfcdd8a
chore(ruff): cleanup setup.py whitespace, comprehensions etc.
Fixes:
replace [f for f in ...] with list(...)
replace else block after return in if true case
use with open() when reading announcement.txt
add trailing , in lists.
whitespace normalizing
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 05 May 2024 18:19:04 -0400 |
| parents | c75defc1c2f0 |
| children | 9c3ec0a5c7fc |
| 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 |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
25 from __future__ import print_function |
|
4660
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
26 _doc = ''' |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
27 %prog [options] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
28 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
|
29 - 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
|
30 spam-files |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
31 - 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
|
32 WARNING: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 ''' |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
37 |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
38 import sys |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
39 from optparse import OptionParser |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
40 from roundup import instance, hyperdb |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
41 |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
42 def main(): |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
43 cmd = OptionParser(usage=_doc) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
44 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
45 ( "-i", "--instance" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
46 , help = "Instance home" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
47 , default = "." |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
48 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
49 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
50 ( "-d", "--designator" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
51 , dest = "designators" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
52 , 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
|
53 "e.g. issue4711" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
54 , action = "append" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
55 , default = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
56 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
57 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
58 ( "-f", "--filename" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
59 , dest = "filenames" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
60 , 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
|
61 , action = "append" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
62 , default = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
63 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
64 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
65 ( "-a", "--action", "--no-dry-run" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
66 , dest = "doit" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
67 , 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
|
68 , action = "store_true" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
69 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
70 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
71 ( "-s", "--file-start-pattern" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
72 , dest = "file_pattern" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
73 , 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
|
74 , action = "append" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
75 , default = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
76 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
77 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
78 ( "-u", "--spam-user" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
79 , dest = "users" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
80 , 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
|
81 , action = "append" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
82 , default = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
83 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
84 cmd.add_option \ |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
85 ( "-q", "--quiet" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
86 , dest = "quiet" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
87 , 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
|
88 , action = "store_true" |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
89 ) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
90 opt, args = cmd.parse_args() |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
91 # open the instance |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
92 if len(args): |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
93 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
|
94 cmd.show_help() |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
95 tracker = instance.open(opt.instance) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
96 db = tracker.open('admin') |
| 4781 | 97 db.tx_Source = "cli" |
| 98 | |
|
4660
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
99 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
|
100 files_to_remove = {} |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 files_to_remove[fid] = True |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 files_to_remove[fid] = True |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
109 files_found = {} |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
110 for d in opt.designators: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
111 clsname, id = hyperdb.splitDesignator(d) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
112 cls = db.getclass(clsname) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 f = db.file.getnode(fid) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
116 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
|
117 files_to_remove[fid] = True |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
118 files_found[fid] = True |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
119 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
|
120 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
|
121 del issuefiles[fid] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
122 if opt.doit: |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
123 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
|
124 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
|
125 # 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
|
126 # 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
|
127 # 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
|
128 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
|
129 newjournal = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
130 for j in journal: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 continue |
|
4660
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
135 changes = dict(j[4]['files']) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
136 # 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
|
137 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
|
138 f = dict.fromkeys(changes['+']) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
139 files_found.update(f) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
140 files_to_remove.update(f) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
141 del changes['+'] |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
142 # change dict in-place |
|
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
143 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
|
144 new_f = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
145 for f in v: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
146 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
|
147 files_found[f] = True |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
148 else: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
149 new_f.append(f) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
150 if new_f : |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
151 changes[k] = new_f |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
152 else: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
153 del changes[k] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
154 msg = [] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
155 if not opt.quiet: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
156 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
|
157 if changes: |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
158 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
|
159 else: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
160 del j[4]['files'] |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
161 if j[4]: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
162 newjournal.append(j) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
163 if not opt.quiet: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
164 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
|
165 elif not opt.quiet: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
166 msg.append ("deleted") |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
167 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
|
168 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
|
169 print(m) |
|
4660
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
170 else: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
171 newjournal.append(j) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
172 journal = newjournal |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
173 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
|
174 db.setjournal(clsname, id, newjournal) |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
175 if opt.doit: |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
176 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
|
177 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
|
178 db.commit() |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
179 else: |
|
5412
c75defc1c2f0
Python 3 preparation: miscellaneous Python scripts not named *.py.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4781
diff
changeset
|
180 print("Database not changed") |
|
4660
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 |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
183 if __name__ == '__main__': |
|
9f507a042c1b
Add a script to remove file-spam from a tracker.
Ralf Schlatterbeck <rsc@runtux.com>
parents:
diff
changeset
|
184 main() |
