From fbb61baf515b78b6f8246335fb2d9b077a29ee1d Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Sun, 22 Nov 2020 21:48:02 +0100 Subject: examples: Rename `introspection/python` -> `python` --- examples/introspection/python/all-async.py | 30 ------------------- examples/introspection/python/miner.py | 43 ---------------------------- examples/introspection/python/query-async.py | 25 ---------------- examples/introspection/python/query-sync.py | 9 ------ examples/python/all-async.py | 30 +++++++++++++++++++ examples/python/miner.py | 43 ++++++++++++++++++++++++++++ examples/python/query-async.py | 25 ++++++++++++++++ examples/python/query-sync.py | 9 ++++++ 8 files changed, 107 insertions(+), 107 deletions(-) delete mode 100755 examples/introspection/python/all-async.py delete mode 100755 examples/introspection/python/miner.py delete mode 100755 examples/introspection/python/query-async.py delete mode 100755 examples/introspection/python/query-sync.py create mode 100755 examples/python/all-async.py create mode 100755 examples/python/miner.py create mode 100755 examples/python/query-async.py create mode 100755 examples/python/query-sync.py diff --git a/examples/introspection/python/all-async.py b/examples/introspection/python/all-async.py deleted file mode 100755 index 70a3b2b1f..000000000 --- a/examples/introspection/python/all-async.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker, GObject - - -def results_ready_cb (obj, result, user_data): - cursor = obj.query_finish (result) - - # This can also be done asynchronously - while (cursor.next (None)): - print cursor.get_string (0) - - user_data.quit () - -def connection_ready_cb (object, result, user_data): - assert user_data - conn = Tracker.SparqlConnection.get_finish (result) - - conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }", - None, - results_ready_cb, - user_data) - - -if __name__ == "__main__": - loop = GObject.MainLoop () - - Tracker.SparqlConnection.get_async (None, connection_ready_cb, loop) - - loop.run () diff --git a/examples/introspection/python/miner.py b/examples/introspection/python/miner.py deleted file mode 100755 index 8bc39d574..000000000 --- a/examples/introspection/python/miner.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import TrackerMiner, GLib, GObject, Gio - - -class MyMiner (TrackerMiner.Miner): - __gtype_name__ = 'MyMiner' - - def __init__ (self): - TrackerMiner.Miner.__init__ (self, - name="MyMiner", - progress=0, - status="fine") - # This shouldn't be needed, but at the moment the - # overrided methods are not called - self.connect ("started", self.started_cb) - - # Say to initable that we are ok - self.init (None) - - def started (self, x): - print "override started" - - def started_cb (self, x): - print "started as callback" - - def stopped (self): - print "override stopped" - - def resumed (self): - print "override resumed" - - def paused (self): - print "override paused" - - def progress (self): - print "override progress" - -if __name__ == "__main__": - m = MyMiner () - m.start () - - GObject.MainLoop().run () diff --git a/examples/introspection/python/query-async.py b/examples/introspection/python/query-async.py deleted file mode 100755 index 1077052dc..000000000 --- a/examples/introspection/python/query-async.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker, GObject - -def results_ready_cb (obj, result, user_data): - cursor = obj.query_finish (result) - - # This can also be done asynchronously - while (cursor.next (None)): - print cursor.get_string (0) - - user_data.quit () - - -if __name__ == "__main__": - loop = GObject.MainLoop () - - # The connection can be requested asynchronously - conn = Tracker.SparqlConnection.get (None) - conn.query_async ("SELECT nie:url(?u) WHERE { ?u a nfo:FileDataObject }", - None, - results_ready_cb, - loop) - - loop.run () diff --git a/examples/introspection/python/query-sync.py b/examples/introspection/python/query-sync.py deleted file mode 100755 index cf8bfd6f6..000000000 --- a/examples/introspection/python/query-sync.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker - -conn = Tracker.SparqlConnection.get (None) -cursor = conn.query ("SELECT ?u WHERE { ?u a nie:InformationElement. }", None) - -while (cursor.next (None)): - print cursor.get_string (0) diff --git a/examples/python/all-async.py b/examples/python/all-async.py new file mode 100755 index 000000000..70a3b2b1f --- /dev/null +++ b/examples/python/all-async.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +import gi +from gi.repository import Tracker, GObject + + +def results_ready_cb (obj, result, user_data): + cursor = obj.query_finish (result) + + # This can also be done asynchronously + while (cursor.next (None)): + print cursor.get_string (0) + + user_data.quit () + +def connection_ready_cb (object, result, user_data): + assert user_data + conn = Tracker.SparqlConnection.get_finish (result) + + conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }", + None, + results_ready_cb, + user_data) + + +if __name__ == "__main__": + loop = GObject.MainLoop () + + Tracker.SparqlConnection.get_async (None, connection_ready_cb, loop) + + loop.run () diff --git a/examples/python/miner.py b/examples/python/miner.py new file mode 100755 index 000000000..8bc39d574 --- /dev/null +++ b/examples/python/miner.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +import gi +from gi.repository import TrackerMiner, GLib, GObject, Gio + + +class MyMiner (TrackerMiner.Miner): + __gtype_name__ = 'MyMiner' + + def __init__ (self): + TrackerMiner.Miner.__init__ (self, + name="MyMiner", + progress=0, + status="fine") + # This shouldn't be needed, but at the moment the + # overrided methods are not called + self.connect ("started", self.started_cb) + + # Say to initable that we are ok + self.init (None) + + def started (self, x): + print "override started" + + def started_cb (self, x): + print "started as callback" + + def stopped (self): + print "override stopped" + + def resumed (self): + print "override resumed" + + def paused (self): + print "override paused" + + def progress (self): + print "override progress" + +if __name__ == "__main__": + m = MyMiner () + m.start () + + GObject.MainLoop().run () diff --git a/examples/python/query-async.py b/examples/python/query-async.py new file mode 100755 index 000000000..1077052dc --- /dev/null +++ b/examples/python/query-async.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +import gi +from gi.repository import Tracker, GObject + +def results_ready_cb (obj, result, user_data): + cursor = obj.query_finish (result) + + # This can also be done asynchronously + while (cursor.next (None)): + print cursor.get_string (0) + + user_data.quit () + + +if __name__ == "__main__": + loop = GObject.MainLoop () + + # The connection can be requested asynchronously + conn = Tracker.SparqlConnection.get (None) + conn.query_async ("SELECT nie:url(?u) WHERE { ?u a nfo:FileDataObject }", + None, + results_ready_cb, + loop) + + loop.run () diff --git a/examples/python/query-sync.py b/examples/python/query-sync.py new file mode 100755 index 000000000..cf8bfd6f6 --- /dev/null +++ b/examples/python/query-sync.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python +import gi +from gi.repository import Tracker + +conn = Tracker.SparqlConnection.get (None) +cursor = conn.query ("SELECT ?u WHERE { ?u a nie:InformationElement. }", None) + +while (cursor.next (None)): + print cursor.get_string (0) -- cgit v1.2.1 From 77bdadfc0c12fb70d7819414fd54ff108dd46b00 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 23 Nov 2020 20:47:25 +0100 Subject: examples: Remove flatpak example There's a more complete example in tracker-miners.git. --- examples/flatpak/org.example.TrackerSandbox.json | 32 ------------------------ 1 file changed, 32 deletions(-) delete mode 100644 examples/flatpak/org.example.TrackerSandbox.json diff --git a/examples/flatpak/org.example.TrackerSandbox.json b/examples/flatpak/org.example.TrackerSandbox.json deleted file mode 100644 index 72e023b13..000000000 --- a/examples/flatpak/org.example.TrackerSandbox.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "app-id" : "org.example.TrackerSandbox", - "runtime" : "org.gnome.Platform", - "runtime-version" : "master", - "sdk" : "org.gnome.Sdk", - "command" : "/bin/sh", - "tags" : [ - "nightly" - ], - "finish-args" : [ - /* Define policy for the XDG Tracker portal */ - "--add-policy=Tracker3.dbus:org.freedesktop.Tracker3.Miner.Files=tracker:Audio" - ], - "modules" : [ - { - "name" : "tracker", - "buildsystem" : "meson", - "config-opts": [ - "-Ddocs=false", - "-Dman=false", - "-Dsystemd_user_services=false" - ], - "sources" : [ - { - "type" : "git", - "url" : "https://gitlab.gnome.org/GNOME/tracker.git", - "branch" : "wip/carlosg/portal" - } - ] - } - ] -} -- cgit v1.2.1 From a06e0404d5b950db8c9fcfc1c0b472ccda799761 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Sun, 22 Nov 2020 21:49:33 +0100 Subject: examples: Remove miner example libtracker-miner is private in Tracker 3. --- examples/python/miner.py | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100755 examples/python/miner.py diff --git a/examples/python/miner.py b/examples/python/miner.py deleted file mode 100755 index 8bc39d574..000000000 --- a/examples/python/miner.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import TrackerMiner, GLib, GObject, Gio - - -class MyMiner (TrackerMiner.Miner): - __gtype_name__ = 'MyMiner' - - def __init__ (self): - TrackerMiner.Miner.__init__ (self, - name="MyMiner", - progress=0, - status="fine") - # This shouldn't be needed, but at the moment the - # overrided methods are not called - self.connect ("started", self.started_cb) - - # Say to initable that we are ok - self.init (None) - - def started (self, x): - print "override started" - - def started_cb (self, x): - print "started as callback" - - def stopped (self): - print "override stopped" - - def resumed (self): - print "override resumed" - - def paused (self): - print "override paused" - - def progress (self): - print "override progress" - -if __name__ == "__main__": - m = MyMiner () - m.start () - - GObject.MainLoop().run () -- cgit v1.2.1 From 98585df9d00a9e57cf6687a56c001ad455f68256 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Sun, 22 Nov 2020 22:09:15 +0100 Subject: examples: Remove all-async.py query It's not clear how this is different from query-async.py. --- examples/python/all-async.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100755 examples/python/all-async.py diff --git a/examples/python/all-async.py b/examples/python/all-async.py deleted file mode 100755 index 70a3b2b1f..000000000 --- a/examples/python/all-async.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker, GObject - - -def results_ready_cb (obj, result, user_data): - cursor = obj.query_finish (result) - - # This can also be done asynchronously - while (cursor.next (None)): - print cursor.get_string (0) - - user_data.quit () - -def connection_ready_cb (object, result, user_data): - assert user_data - conn = Tracker.SparqlConnection.get_finish (result) - - conn.query_async ("SELECT ?u WHERE { ?u a nie:InformationElement. }", - None, - results_ready_cb, - user_data) - - -if __name__ == "__main__": - loop = GObject.MainLoop () - - Tracker.SparqlConnection.get_async (None, connection_ready_cb, loop) - - loop.run () -- cgit v1.2.1 From 0da4cd399ea9417e90a8290a1c3b0a734284a212 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 23 Nov 2020 20:48:12 +0100 Subject: examples: Move Python query examples to tracker-miners. These query the Miner FS, so they should go with it. --- examples/python/query-async.py | 25 ------------------------- examples/python/query-sync.py | 9 --------- 2 files changed, 34 deletions(-) delete mode 100755 examples/python/query-async.py delete mode 100755 examples/python/query-sync.py diff --git a/examples/python/query-async.py b/examples/python/query-async.py deleted file mode 100755 index 1077052dc..000000000 --- a/examples/python/query-async.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker, GObject - -def results_ready_cb (obj, result, user_data): - cursor = obj.query_finish (result) - - # This can also be done asynchronously - while (cursor.next (None)): - print cursor.get_string (0) - - user_data.quit () - - -if __name__ == "__main__": - loop = GObject.MainLoop () - - # The connection can be requested asynchronously - conn = Tracker.SparqlConnection.get (None) - conn.query_async ("SELECT nie:url(?u) WHERE { ?u a nfo:FileDataObject }", - None, - results_ready_cb, - loop) - - loop.run () diff --git a/examples/python/query-sync.py b/examples/python/query-sync.py deleted file mode 100755 index cf8bfd6f6..000000000 --- a/examples/python/query-sync.py +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env python -import gi -from gi.repository import Tracker - -conn = Tracker.SparqlConnection.get (None) -cursor = conn.query ("SELECT ?u WHERE { ?u a nie:InformationElement. }", None) - -while (cursor.next (None)): - print cursor.get_string (0) -- cgit v1.2.1 From 462bc3d956a5db81a3f4dd805d2421a3f9339cdc Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Sun, 22 Nov 2020 22:16:58 +0100 Subject: examples: Add endpoint example --- examples/meson.build | 1 + examples/python/endpoint.py | 79 +++++++++++++++++++++++++++++++++++++++++++++ examples/python/meson.build | 22 +++++++++++++ meson.build | 2 +- utils/meson.build | 2 ++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100755 examples/python/endpoint.py create mode 100644 examples/python/meson.build diff --git a/examples/meson.build b/examples/meson.build index f788edc7d..9cfe5f8b4 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -1 +1,2 @@ subdir('libtracker-sparql') +subdir('python') diff --git a/examples/python/endpoint.py b/examples/python/endpoint.py new file mode 100755 index 000000000..503e61445 --- /dev/null +++ b/examples/python/endpoint.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 +# Copyright (C) 2020, Sam Thursfield +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + + +"""Demonstrates publishing a database over DBus.""" + +import gi +gi.require_version('Tracker', '3.0') +from gi.repository import Gio +from gi.repository import GLib +from gi.repository import Tracker + +import logging +import os +import sys +import tempfile + + +def main(): + logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) + + tmpdir = tempfile.mkdtemp(prefix='tracker-test-') + + # Where the database is stored. + store_path = Gio.File.new_for_path(tmpdir) + + # The database schemas. + ontology_path = Tracker.sparql_get_ontology_nepomuk() + if 'TEST_ONTOLOGIES_DIR' in os.environ: + ontology_path = Gio.File.new_for_path(os.environ['TEST_ONTOLOGIES_DIR']) + + cancellable = None + + # Create a new, empty database. + conn = Tracker.SparqlConnection.new( + Tracker.SparqlConnectionFlags.NONE, + store_path, + ontology_path, + cancellable) + + bus = Gio.bus_get_sync(Gio.BusType.SESSION, cancellable) + unique_name = bus.get_unique_name() + + # Publish our endpoint on DBus. + endpoint = Tracker.EndpointDBus.new(conn, bus, None, cancellable) + + print(f"Exposing a Tracker endpoint on bus name {unique_name}") + print() + print(f"Try connecting over D-Bus using `tracker3 sparql`:") + print() + print(f" tracker3 sparql --dbus-service={unique_name} -q ...") + + loop = GLib.MainLoop.new(None, False) + + if os.environ.get('TRACKER_EXAMPLES_AUTOMATED_TEST'): + GLib.timeout_add(10, lambda *args: loop.quit(), None) + else: + print() + print(f"Press CTRL+C to quit.") + + loop.run() + + +main() diff --git a/examples/python/meson.build b/examples/python/meson.build new file mode 100644 index 000000000..39c464520 --- /dev/null +++ b/examples/python/meson.build @@ -0,0 +1,22 @@ +python = find_program('python3') + +env = environment() +env.prepend('GI_TYPELIB_PATH', tracker_sparql_uninstalled_dir) +env.prepend('LD_LIBRARY_PATH', tracker_sparql_uninstalled_dir) +env.prepend('PYTHONPATH', tracker_uninstalled_testutils_dir) +env.set('TRACKER_EXAMPLES_AUTOMATED_TEST', '1') +env.set('TEST_ONTOLOGIES_DIR', tracker_uninstalled_nepomuk_ontologies_dir) + +sandbox_python_args = ['-m', 'trackertestutils', '--store-tmpdir', '--dbus-config', meson.current_build_dir() / '..' / '..' / 'tests' / 'test-bus.conf'] + +examples = [ + 'endpoint', +] + +foreach example_name: examples + file = meson.current_source_dir() / '@0@.py'.format(example_name) + test(example_name, python, + args: sandbox_python_args + [file], + env: env, + suite: 'examples') +endforeach diff --git a/meson.build b/meson.build index a549c24fa..7ba4cd8a9 100644 --- a/meson.build +++ b/meson.build @@ -305,7 +305,6 @@ typelib_dir = gobject_introspection.get_pkgconfig_variable('typelibdir', subdir('src') subdir('docs') -subdir('examples') subdir('utils') test_c_args = tracker_c_args + [ @@ -319,6 +318,7 @@ tracker_uninstalled_stop_words_dir = join_paths(meson.current_source_dir(), 'src tracker_uninstalled_testutils_dir = join_paths(meson.current_source_dir(), 'utils') subdir('tests') +subdir('examples') subdir('po') diff --git a/utils/meson.build b/utils/meson.build index c9431bb74..d571a582b 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -1,3 +1,5 @@ subdir('mtp') subdir('tracker-resdump') subdir('trackertestutils') + +utils_dir = meson.current_source_dir() -- cgit v1.2.1 From 2c9d7d4887e78ef98363c06718c8a527695d6ab2 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Mon, 23 Nov 2020 20:47:46 +0100 Subject: examples: Add README --- examples/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 examples/README.md diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..bb29bf7b0 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,6 @@ +# Tracker examples + +More examples can be found in the Tracker Miners project, some of which +are more relevant to newcomers than these. + +See https://gitlab.gnome.org/GNOME/tracker-miners/ in the examples/ subfolder. -- cgit v1.2.1