[sugar] [PATCH] Deleting items from the Journal

Martin Dengler martin at martindengler.com
Thu Oct 30 20:26:09 EDT 2008


In case anyone finds them useful or they annoy someone into doing a
better job, below are some patches that can be used to clean up your
journal, as in:

lsjournal -W -t "Terminal Activity" -u | remove-from-journal --delete
lsjournal -W -t "Page Load Error" -u | remove-from-journal --delete

To apply, this worked for me (on jhbuild, and of course I developed
them on a joyride XO, so it probably works there and on 767):

sudo su -
cd /usr/bin
patch < thismail.txt

Martin


From ea58945e59874a9b1b36c846ea7fbe3fd56a130b Mon Sep 17 00:00:00 2001
From: Martin Dengler <martin at martindengler.com>
Date: Sun, 26 Oct 2008 20:18:24 +0000
Subject: [PATCH] add remove-from-journal script

---
 remove-from-journal |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100755 remove-from-journal

diff --git a/remove-from-journal b/remove-from-journal
new file mode 100755
index 0000000..42064b3
--- /dev/null
+++ b/remove-from-journal
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+#
+#####
+#
+# Copyright (c) 2008 Martin Dengler
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+#####
+import optparse
+import os
+import sys
+
+from sugar.datastore import datastore
+
+# Set up things so that this script can run in a terminal.
+if 'DBUS_SESSION_BUS_ADDRESS' not in os.environ:
+    os.environ['DBUS_SESSION_BUS_ADDRESS'] = 'unix:path=/tmp/olpc-session-bus'
+if 'DISPLAY' not in os.environ:
+    os.environ['DISPLAY'] = ':0.0'
+
+parser = optparse.OptionParser(usage="%prog [--delete]\n\n"
+                               " expects a list of uids on standard input,"
+                               " one per line")
+parser.add_option("--delete", action="store_true", default=False,
+                  help="DELETE the matches - WARNING WILL LOSE DATA")
+options, args = parser.parse_args()
+
+for uid in sys.stdin:
+    uid = uid.strip()
+    if options.delete:
+        datastore.delete(uid)
+            
-- 
1.5.5.1


From 8d4f44bd94be3d0bc5965e08f26611d3bf2068a9 Mon Sep 17 00:00:00 2001
From: Martin Dengler <martin at martindengler.com>
Date: Sun, 26 Oct 2008 21:58:33 +0000
Subject: [PATCH] add --without-files to find only objects lacking files

---
 lsjournal |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/lsjournal b/lsjournal
index 7083002..852dc18 100755
--- a/lsjournal
+++ b/lsjournal
@@ -60,6 +60,11 @@ def build_option_parser():
      help="show all metadata and properties",
      default=False)
 
+    parser.add_option("-W", "--without-files", action="store_true",
+     dest="without_files",
+     help="only return items without a file path",
+     default=False)
+
     return parser
 
 if __name__ == "__main__":
@@ -86,7 +91,9 @@ if __name__ == "__main__":
     objects, count = datastore.find(query, sorting='-mtime')
 
     for i in range(count):
-        if not options.all and not objects[i].file_path:
+        if ((options.without_files and objects[i].file_path) or
+            (not (options.all or options.without_files)
+             and not objects[i].file_path)):
             objects[i].destroy()
             continue
         if options.debug:
-- 
1.5.5.1



From e98b49966a7a4c616701e02945e3f74acc4cd671 Mon Sep 17 00:00:00 2001
From: Martin Dengler <martin at martindengler.com>
Date: Sun, 26 Oct 2008 23:18:07 +0000
Subject: [PATCH] support -S option to allow -W to ignore files below a certain size

---
 lsjournal |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/lsjournal b/lsjournal
index 852dc18..43723c4 100755
--- a/lsjournal
+++ b/lsjournal
@@ -65,8 +65,15 @@ def build_option_parser():
      help="only return items without a file path",
      default=False)
 
+    parser.add_option("-S", "--ignore-files-smaller-than",
+     dest="ignore_files_smaller_than", type=int,
+     help="consider items with a file smaller than this limit to have no file")
+
     return parser
 
+def realpath(dsobject):
+    return '/home/olpc/.sugar/default/datastore/store/' + dsobject.object_id
+
 if __name__ == "__main__":
 
     # Set up things so that this script can run in a terminal.  We connect to
@@ -91,9 +98,14 @@ if __name__ == "__main__":
     objects, count = datastore.find(query, sorting='-mtime')
 
     for i in range(count):
-        if ((options.without_files and objects[i].file_path) or
-            (not (options.all or options.without_files)
-             and not objects[i].file_path)):
+        has_file = objects[i].file_path is not None
+        if has_file and options.ignore_files_smaller_than and \
+                (os.stat(realpath(objects[i])).st_size
+                 < options.ignore_files_smaller_than):
+            has_file = False
+        
+        if ((    has_file and options.without_files) or
+            (not has_file and not (options.all or options.without_files))):
             objects[i].destroy()
             continue
         if options.debug:
-- 
1.5.5.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.laptop.org/pipermail/sugar/attachments/20081031/73aef327/attachment.pgp 


More information about the Sugar mailing list