Merge lp:~3v1n0/bamf/class-to-index-file into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 530
Merged at revision: 526
Proposed branch: lp:~3v1n0/bamf/class-to-index-file
Merge into: lp:bamf/0.4
Diff against target: 188 lines (+120/-6)
2 files modified
debian/bamfdaemon.postinst (+74/-3)
src/bamf-matcher.c (+46/-3)
To merge this branch: bzr merge lp:~3v1n0/bamf/class-to-index-file
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Loïc Minier Approve
Brandon Schaefer (community) Approve
Review via email: mp+155979@code.launchpad.net

Commit message

debian/bamfdaemon.postinst: write it in multiline and add support for StartupWMClass

And other properties such as NoDisplay and OnlyShowIn.

Also rewritten the bamfdaemon.postinst to use a multi-line perl script for easier review.

Description of the change

Save to the /usr/share/applications/bamf.index columns containing extra parameters such as StartupWMClass, NoDisplay and OnlyShowIn. Update the bamf-matcher to use them instead of parse these from .desktop files, saving some IO.

To post a comment you must log in.
lp:~3v1n0/bamf/class-to-index-file updated
527. By Marco Trevisan (Treviño)

debian/bamfdaemon.postinst: indentation fix

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

Hey,

r525: ok; the bits of Perl are written like C, but eh decently readable and it seems like they will work :-)

r526:
- strstr() seems a bit weak to match OnlyShowIn; that would work for now, but what if we want to implement e.g. Unity-Next in .desktop files? might be best to split on ";" properly here
- is it ok to g_hash_table_insert direclty instead of using something like insert_desktop_file_class_into_table?

r527: ok

Some problems not directly related, but worth fixing:
* no version information in bamf index; you could have a version depending on the filename (e.g. this could be bamf-2.0.index)
* should this be in /var/cache or /var/lib, but not in /usr/share? it's actually only modified when packages are added/removed (.desktop files), but seems a bit weird to have a locally generated file under /usr/share
* generally, I haven't checked how whitespace is handled in .desktop files (e.g. if the .desktop file contains trailing or leading spaces or tabs around key names / key values)

(not sure how ~/ .desktop are handled, but I guess that's another story)

Thanks,

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Hey,
>
> r525: ok; the bits of Perl are written like C, but eh decently readable and it
> seems like they will work :-)

We needed to clean them up :)

> r526:
> - strstr() seems a bit weak to match OnlyShowIn; that would work for now, but
> what if we want to implement e.g. Unity-Next in .desktop files? might be best
> to split on ";" properly here

Ok, it was my same idea at the beginning, then I forgot to finish it waiting to test this :)

> - is it ok to g_hash_table_insert direclty instead of using something like
> insert_desktop_file_class_into_table?

Yes. Using insert_desktop_file_class_into_table causes to open the file again, and so to use io-blocking functions, while we want to avoid this since this data is already provided by the index file.

> r527: ok
>
> Some problems not directly related, but worth fixing:
> * no version information in bamf index; you could have a version depending on
> the filename (e.g. this could be bamf-2.0.index)

Yes, it makes sense... Even if this file will be always built before the new bamf will able to use it so it should be quite safe.

> * should this be in /var/cache or /var/lib, but not in /usr/share? it's
> actually only modified when packages are added/removed (.desktop files), but
> seems a bit weird to have a locally generated file under /usr/share

Yes, probably true. But the idea is that you can also add a bamf.index file inside another monitored folder and use it instead of manual directory parsing.

> * generally, I haven't checked how whitespace is handled in .desktop files
> (e.g. if the .desktop file contains trailing or leading spaces or tabs around
> key names / key values)

There shouldn't be issues for this. Also luckily there are no problems with the provided .desktop files in raring, but maybe having stronger regex could help.

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM. Tests pass as well.

review: Approve
lp:~3v1n0/bamf/class-to-index-file updated
528. By Marco Trevisan (Treviño)

debian/bamfdaemon.postinst: trim the parsed strings

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/class-to-index-file updated
529. By Marco Trevisan (Treviño)

Use g_strsplit to handle OnlyShowIn values

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/class-to-index-file updated
530. By Marco Trevisan (Treviño)

BamfMatcher: use bamf-2.index file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Loïc Minier (lool) wrote :

Looks good; thanks for the fixes, now why does it break jenkins?
cc: error: unrecognized command line option '--c-include=libbamf/libbamf.h'

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> Looks good; thanks for the fixes, now why does it break jenkins?
> cc: error: unrecognized command line option '--c-include=libbamf/libbamf.h'

There have been changes to glib and the gobject introspection not related to this branch, the fixes are landing right now in lp:~3v1n0/bamf/fix-trunk-compilation-tests

Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/bamfdaemon.postinst'
--- debian/bamfdaemon.postinst 2012-10-17 06:02:25 +0000
+++ debian/bamfdaemon.postinst 2013-03-28 20:01:22 +0000
@@ -1,13 +1,84 @@
1#! /bin/sh1#! /bin/sh
2set -e2set -e
33
4BAMF_INDEX_NAME="bamf-2.index"
5
4if [ "$1" = "configure" ] || [ "$1" = "triggered" ]; then6if [ "$1" = "configure" ] || [ "$1" = "triggered" ]; then
5 if [ -d /usr/share/applications ]; then7 if [ -d /usr/share/applications ]; then
6 # rebuild index8 # rebuild index
7 I=/usr/share/applications/bamf.index9 I=/usr/share/applications/$BAMF_INDEX_NAME
8 echo "Rebuilding $I..."10 echo "Rebuilding $I..."
9 rm -f $I11 rm -f $I
10 perl -e 'use File::Find; my $dir_name; sub strip_exec { my $f = $_; return unless $f =~ /\.desktop$/; return unless ("$File::Find::dir" eq "$dir_name"); my @lines; open F, $f; @lines = <F>; close F; my $in_desktop_entry = 0; foreach (@lines) { if (/^\[\s*(.+)\s*\]/) { $in_desktop_entry = ($1 eq "Desktop Entry"); } if (/^Exec=(.+)$/ && $in_desktop_entry) { print "$f\t$1\n"; } } }; $dir_name = $ARGV[-1]; $dir_name = $1 if($dir_name=~/(.*)\/$/); find(\&strip_exec, $dir_name);' /usr/share/applications > $I.new || rm -f $I.new12 perl -e '
13use File::Find;
14my $dir_name;
15
16sub strip_exec
17{
18 my $f = $_;
19 return unless $f =~ /\.desktop$/;
20 return unless ("$File::Find::dir" eq "$dir_name");
21 my @lines;
22 open F, $f;
23 @lines = <F>;
24 close F;
25 my $in_desktop_entry = 0;
26 my $exec = "";
27 my $class = "";
28 my $no_display = "false";
29 my $only_show_in = "";
30
31 foreach (@lines)
32 {
33 if (/^\[\s*(.+)\s*\]/)
34 {
35 $was_in_desktop = $in_desktop_entry;
36 $in_desktop_entry = ($1 eq "Desktop Entry");
37
38 if ($was_in_desktop and !$in_desktop_entry)
39 {
40 last;
41 }
42 }
43
44 if ($in_desktop_entry)
45 {
46 if (/^Exec=(.+)$/)
47 {
48 $exec = $1;
49 $exec =~ s/^\s+|\s+$//g;
50 }
51
52 if (/^NoDisplay=(.+)$/)
53 {
54 $no_display = $1;
55 $no_display =~ s/^\s+|\s+$//g;
56 }
57
58 if (/^OnlyShowIn=(.+)$/)
59 {
60 $only_show_in = $1;
61 $only_show_in =~ s/^\s+|\s+$//g;
62 }
63
64 if (/^StartupWMClass=(.+)$/)
65 {
66 $class = $1;
67 $class =~ s/^\s+|\s+$//g;
68 }
69 }
70 }
71
72 if ($exec ne "")
73 {
74 print "$f\t$exec\t$class\t$only_show_in\t$no_display\n";
75 }
76};
77
78$dir_name = $ARGV[-1];
79$dir_name = $1 if($dir_name=~/(.*)\/$/);
80find(\&strip_exec, $dir_name);' /usr/share/applications > $I.new || rm -f $I.new
81
11 [ -e $I.new ] && mv $I.new $I || true82 [ -e $I.new ] && mv $I.new $I || true
12 fi83 fi
13fi84fi
1485
=== modified file 'src/bamf-matcher.c'
--- src/bamf-matcher.c 2013-03-06 04:29:49 +0000
+++ src/bamf-matcher.c 2013-03-28 20:01:22 +0000
@@ -31,6 +31,8 @@
31#endif31#endif
32#include <strings.h>32#include <strings.h>
3333
34#define BAMF_INDEX_NAME "bamf-2.index"
35
34G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON);36G_DEFINE_TYPE (BamfMatcher, bamf_matcher, BAMF_DBUS_TYPE_MATCHER_SKELETON);
35#define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \37#define BAMF_MATCHER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE(obj, \
36 BAMF_TYPE_MATCHER, BamfMatcherPrivate))38 BAMF_TYPE_MATCHER, BamfMatcherPrivate))
@@ -938,6 +940,7 @@
938 GDataInputStream *input;940 GDataInputStream *input;
939 char *line;941 char *line;
940 char *directory;942 char *directory;
943 const char *current_desktop;
941 gsize length;944 gsize length;
942945
943 file = g_file_new_for_path (index_file);946 file = g_file_new_for_path (index_file);
@@ -952,16 +955,51 @@
952 return;955 return;
953 }956 }
954957
958 length = 0;
959 current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
955 directory = g_path_get_dirname (index_file);960 directory = g_path_get_dirname (index_file);
956 input = g_data_input_stream_new (G_INPUT_STREAM (stream));961 input = g_data_input_stream_new (G_INPUT_STREAM (stream));
957962
963 if (current_desktop && current_desktop[0] == '\0')
964 current_desktop = NULL;
965
958 while ((line = g_data_input_stream_read_line (input, &length, NULL, NULL)))966 while ((line = g_data_input_stream_read_line (input, &length, NULL, NULL)))
959 {967 {
960 char *exec;968 char *exec;
961 char *filename;969 char *filename;
970 const char *class;
971 const char *show_in;
962 GString *desktop_id;972 GString *desktop_id;
963973
964 gchar **parts = g_strsplit (line, "\t", 3);974 /* Order is: 0 Desktop-Id, 1 Exec, 2 class, 3 ShowIn, 4 NoDisplay */
975 gchar **parts = g_strsplit (line, "\t", 5);
976
977 show_in = parts[3];
978
979 if (current_desktop && show_in && show_in[0] != '\0')
980 {
981 gchar **sub_parts = g_strsplit (show_in, ";", -1);
982 gboolean found_current = FALSE;
983 int i = 0;
984
985 for (i = 0; sub_parts[i]; ++i)
986 {
987 if (g_ascii_strcasecmp (sub_parts[i], current_desktop) == 0)
988 {
989 found_current = TRUE;
990 break;
991 }
992 }
993
994 g_strfreev (sub_parts);
995
996 if (!found_current)
997 {
998 length = 0;
999 g_strfreev (parts);
1000 continue;
1001 }
1002 }
9651003
966 char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]);1004 char *tmp = bamf_matcher_get_trimmed_exec (self, parts[1]);
967 g_free (parts[1]);1005 g_free (parts[1]);
@@ -974,7 +1012,12 @@
974 g_string_truncate (desktop_id, desktop_id->len - 8);1012 g_string_truncate (desktop_id, desktop_id->len - 8);
9751013
976 insert_data_into_tables (self, filename, exec, desktop_id->str, desktop_file_table, desktop_id_table);1014 insert_data_into_tables (self, filename, exec, desktop_id->str, desktop_file_table, desktop_id_table);
977 insert_desktop_file_class_into_table (self, filename, desktop_class_table);1015
1016 class = parts[2];
1017 if (class && class[0] != '\0')
1018 {
1019 g_hash_table_insert (desktop_class_table, g_strdup (filename), g_strdup (class));
1020 }
9781021
979 g_string_free (desktop_id, TRUE);1022 g_string_free (desktop_id, TRUE);
980 g_free (line);1023 g_free (line);
@@ -1349,7 +1392,7 @@
13491392
1350 bamf_matcher_add_new_monitored_directory (self, directory);1393 bamf_matcher_add_new_monitored_directory (self, directory);
13511394
1352 bamf_file = g_build_filename (directory, "bamf.index", NULL);1395 bamf_file = g_build_filename (directory, BAMF_INDEX_NAME, NULL);
13531396
1354 if (g_file_test (bamf_file, G_FILE_TEST_EXISTS))1397 if (g_file_test (bamf_file, G_FILE_TEST_EXISTS))
1355 {1398 {

Subscribers

People subscribed via source and target branches