Canonical Voices

Posts tagged with 'gnome'

pitti

just released a new PyGObject, for GNOME 3.7.2 which is due on Wednesday.

In this version PyGObject went through some major refactoring: Some 5.000 lines of static bindings were removed and replaced with proper introspection and some overrides for backwards compatibility, and the static/GI/overrides code structure was simplified. For the developer this means that you can now use the full GLib API, a lot of which was previously hidden by old and incomplete static bindings; also you can and should now use the officially documented GLib API instead of PyGObject’s static one, which has been marked as deprecated. For PyGObject itself this change means that the code structure is now a lot simpler to understand, all the bugs in the static GLib bindings are gone, and the GLib bindings will not go out of sync any more.

Lots of new tests were written to ensure that the API is backwards compatible, but experience teaches that ther is always the odd corner case which we did not cover. So if your code does not work any more with 3.7.2, please do report bugs.

Another important change is that if you build pygobject from source, it now defaults to using Python 3 if installed. As before, you can build for Python 2 with PYTHON=python2.7 or the new --with-python=python2.7 configure option.

This release also brings several marshalling fixes, docstring improvements, support for code coverage, and other bug fixes.

Thanks to all contributors!

Summary of changes (see changelog for complete details):

  • [API change] Drop almost all static GLib bindings and replace them with proper introspection. This gets rid of several cases where the PyGObject API was not matching the real GLib API, makes the full GLib API available through introspection, and makes the code smaller, easier to maintain. For backwards compatibility, overrides are provided to emulate the old static binding API, but this will throw a PyGIDeprecationWarning for the cases that diverge from the official API (in particular, GLib.io_add_watch() and GLib.child_watch_add() being called without a priority argument). (Martin Pitt, Simon Feltman)
  • [API change] Deprecate calling GLib API through the GObject namespace. This has always been a misnomer with introspection, and will be removed in a later version; for now this throws a PyGIDeprecationWarning.
  • [API change] Do not bind gobject_get_data() and gobject_set_data(). These have been deprecated for a cycle, now dropped entirely. (Steve Frécinaux) (#641944)
  • [API change] Deprecate void pointer fields as general PyObject storage. (Simon Feltman) (#683599)
  • Add support for GVariant properties (Martin Pitt)
  • Add type checking to GVariant argument assignment (Martin Pitt)
  • Fix marshalling of arrays of struct pointers to Python (Carlos Garnacho) (#678620)
  • Fix Gdk.Atom to have a proper str() and repr() (Martin Pitt) (#678620)
  • Make sure g_value_set_boxed does not cause a buffer overrun with GStrvs (Simon Feltman) (#688232)
  • Fix leaks with GValues holding boxed and object types (Simon Feltman) (#688137)
  • Add doc strings showing method signatures for gi methods (Simon Feltman) (#681967)
  • Set Property instance doc string and blurb to getter doc string (Simon Feltman) (#688025)
  • Add GObject.G_MINSSIZE (Martin Pitt)
  • Fix marshalling of GByteArrays (Martin Pitt)
  • Fix marshalling of ssize_t to smaller ints (Martin Pitt)
  • Add support for lcov code coverage, and add a lot of missing GIMarshallingTests and g-i Regress tests. (Martin Pitt)
  • pygi-convert: remove deprecated GLib ? GObject conversions (Jose Rostagno)
  • Add support for overriding GObject.Object (Simon Feltman) (#672727)
  • Add –with-python configure option (Martin Pitt)
  • Do not prefer unversioned “python” when configuring, as some distros have “python” as Python 3. Use Python 3 by default if available. Add –with-python configure option as an alternative to setting $PYTHON, whic is more discoverable. (Martin Pitt)
  • Fix property lookup in class hierarchy (Daniel Drake) (#686942)
  • Move property and signal creation into _class_init() (Martin Pitt) (#686149)
  • Fix duplicate symbols error on OSX (John Ralls)
  • [API add] Add get_introspection_module for getting un-overridden modules (Simon Feltman) (#686828)
  • Work around wrong 64 bit constants in GLib Gir (Martin Pitt) (#685022)
  • Mark GLib.Source.get_current_time() as deprecated (Martin Pitt)
  • Fix OverflowError in source_remove() (Martin Pitt) (#684526)

Read more
pitti

With python-dbusmock you can provide mocks for arbitrary D-BUS services for your test suites or if you want to reproduce a bug.

However, when writing actual tests for gnome-settings-daemon etc. I noticed that it is rather cumbersome to always have to set up the “skeleton” of common services such as UPower. python-dbusmock 0.2 now introduces the concept of “templates” which provide those skeletons for common standard services so that your code only needs to set up the particular properties and specific D-BUS objects that you need. These templates can be parameterized for common customizations, and they can provide additional convenience methods on the org.freedesktop.DBus.Mock interface to provide more abstract functionality like “add a battery”.

So if you want to pretend you have one AC and a half-charged battery, you can now simply do

  def setUp(self):
     (self.p_mock, self.obj_upower) = self.spawn_server_template('upower', {})

  def test_ac_bat(self):
     self.obj_upower.AddAC('mock_AC', 'Mock AC')
     self.obj_upower.AddChargingBattery('mock_BAT', 'Mock Battery', 50.0, 1200)

Or, if your code is not in Python, use the CLI/D-BUS interface, like in shell:

  # start a fake system bus
  eval `dbus-launch`
  export DBUS_SYSTEM_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS

  # start mock upower on the fake bus
  python3 -m dbusmock --template upower &

  # add devices
  gdbus call --system -d org.freedesktop.UPower -o /org/freedesktop/UPower \
      -m org.freedesktop.DBus.Mock.AddAC mock_ac 'Mock AC'
  gdbus call --system -d org.freedesktop.UPower -o /org/freedesktop/UPower \
      -m org.freedesktop.DBus.Mock.AddChargingBattery mock_bat 'Mock Bat' 50.0 1200

In both cases upower --dump or gnome-power-statistics will show you the expected devices (of course you need to run that within the environment of the fake $DBUS_SYSTEM_BUS_ADDRESS, or run the mock on the real system bus as root).

Iftikhar Ahmad contributed a template for NetworkManager, which allows you to easily set up ethernet and wifi devices and wifi access points. See pydoc3 dbusmock.templates.networkmanager for details and the test cases for how this looks like in practice.

I just released python-dbusmock 0.2.1 and uploaded the new version to Debian experimental. I will sync it into Ubuntu Raring in a few hours.

Read more
pitti

I just released PyGObject 3.4.2, a bug fix release for GNOME 3.6.2.

Thanks to all contributors!

  • Fix marshalling of GByteArrays (Martin Pitt)
  • Fix marshalling of ssize_t to smaller ints (Martin Pitt)
  • Fix crash with GLib.child_watch_add (Daniel Narvaez) (#688067)
  • Fix various bugs in GLib.IOChannel (Martin Pitt)
  • Work around wrong 64 bit constants in GLib Gir (Martin Pitt) (#685022)
  • Fix OverflowError in source_remove() (Martin Pitt) (#684526)
  • Fix Signal decorator to not use base class gsignals dict (Simon Feltman) (#686496)

Read more
pitti

A few days ago Olav Vitters announced the GNOME 3.8 goal of porting to Python 3.

This has been discussed on desktop-devel-list@ in the past days, and the foundations for this are now ready:

  • pygobject now has a –with-python option. (commit)
  • JHBuild now defaults to building pygobject for Python 3, but introduces a “pygobject-python2″ project for the transition phase which provides pygobject built for Python 2. (commit)
  • All dependencies to “pygobject” were changed to “pygobject-python2″ to avoid breaking modules. (commit).

So in theory your modules should continue to build and work in jhbuild just fine. Once you ported a module to Python 3, please switch the dependency back to “pygobject” in jhbuild. (This is now also mentioned on https://live.gnome.org/GnomeGoals/Python3Porting)

Please don’t hesitate to ask me or any fellow PyGObject maintainer in cases of trouble; I’m “pitti” in #python on irc.gnome.org.

Thanks!

Read more
pitti

For writing tests for GVFS (current tests, proposed improvements) I want to run Samba as normal user, so that we can test gvfs’ smb backend without root privileges and thus can run them safely and conveniently in a “make check” environment for developers and in JHBuild for continuous integration testing. Before these tests could only run under gvfs-testbed, which needs root.

Unlike other servers such as ssh or ftp, this turned out surprisingly non-obvious and hard, so I want to document it in this blog post for posterity’s benefit.

Running the server

Running smbd itself is mainly an exercise of figuring out all the options that you need to set; Alex Larsson and I had some fun figuring out all the quirks and hiccups that happen between Ubuntu’s and Fedora’s packaging and 3.6 vs. 4.0, but finally arrived at something working.

First, you need to create an empty directory where smbd can put all its databases and state files in. For tests you would use mkdtemp(), but for easier reading I just assume mkdir /tmp/samba here.

The main knowledge is in the Samba configuration file, let’s call it /tmp/smb.conf:

[global]
workgroup = TESTGROUP
interfaces = lo 127.0.0.0/8
smb ports = 1445
log level = 2
map to guest = Bad User
passdb backend = smbpasswd
smb passwd file = /tmp/smbpasswd
lock directory = /tmp/samba
state directory = /tmp/samba
cache directory = /tmp/samba
pid directory = /tmp/samba
private dir = /tmp/samba
ncalrpc dir = /tmp/samba

[public]
path = /tmp/public
guest ok = yes

[private]
path = /tmp/private
read only = no

For running this as a normal user you need to set a port > 1024, so this uses 1445 to resemble the original (privileged) port 445. The map to guest line makes anonymous logins work on Fedora/Samba 4.0 (I’m not sure whether it’s a distribution or a version issue). Don’t ask about “dir” vs. “directory”, that’s an inconsistency in Samba; with above names it works on both 3.6 and 4.0.

We use the old “smbpasswd” backend as shipping large tdb files is usually too inconvenient and brittle for test suites. I created an smbpasswd file by running smbpasswd on a “real” Samba installation, and then using pdbedit to convert it to a smbpasswd file:

sudo smbpasswd -a martin
sudo pdbedit -i tdbsam:/var/lib/samba/passdb.tdb -e smbpasswd:/tmp/smbpasswd

The result for password “foo” is

myuser:0:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:AC8E657F83DF82BEEA5D43BDAF7800CC:[U          ]:LCT-507C14C7:

which you are welcome to copy&paste (you can replace “myuser” with any valid user name, of course).

This also defines two shares, one public, one authenticated. You need to create the directories and populate them a bit:

mkdir /tmp/public /tmp/private
echo hello > /tmp/public/hello.txt
echo secret > /tmp/private/myfile.txt

Now you can run the server with

smbd -iFS -s /tmp/smb.conf

The main problem with this approach is that smbd exits (“Server exit (failed to receive smb request)”) after a client terminates, so you need to write your tests in a way to only run one connection/request per test, or to start smbd in a loop.

Running the client

If you merely use the smbclient command line tool, this is rather simple: It has a -p option for specifying the port:

$ smbclient -p 1445 //localhost/private
Enter martin's password: [enter "foo" here]
Domain=[TESTGROUP] OS=[Unix] Server=[Samba 3.6.6]
smb: \> dir
  .                                   D        0  Wed Oct 17 08:28:23 2012
  ..                                  D        0  Wed Oct 17 08:31:24 2012
  myfile.txt                                   7  Wed Oct 17 08:28:23 2012

In the case of gvfs it wasn’t so simple, however. Surprisingly, libsmbclient does not have an API to set the port, it always assumes 445. smbclient itself uses some internal “libcli” API which does have a way to change the port, but it’s not exposed through libsmbclient. However, Alex and I found some mailing list posts ([1], [2]) that mention $LIBSMB_PROG, and it’s also mentioned in smbclient’s manpage. It doesn’t quite work as advertised in the second ML post (you can’t set it to smbd, smbd apparently doesn’t speak the socket protocol over stdin/stdout), and it’s not being used anywhere in the current Samba sources, but what does work is to use good old netcat:

export LIBSMB_PROG="nc localhost 1445"

with that, you can use smbclient or any program using libsmbclient to talk to our test smb server running as user.

Read more
pitti

I just released PyGObject 3.4.1, in time for the GNOME 3.6.1 release on Wednesday.

This version provides a nice set of bug fixes. no API changes.

Thanks to all contributors!

Complete list of changes:

  • Skip Regress tests with –disable-cairo (Martin Pitt) (#685094)
  • _pygi_marshal_from_py_uint64: Re-fix check of negative values (Martin Pitt) (#685000)
  • Fix leak with python callables as closure argument. (Simon Feltman) (#685598)
  • Gio overrides: Handle setting GSettings enum keys (Martin Pitt) (#685947)
  • tests: Check reading GSettings enums in Gio overrides (Martin Pitt)
  • Fix unsigned values in GArray/GList/GSList/GHash (Martin Pitt) (#685860)
  • build: Fix srcdir != builddir (Colin Walters)
  • _pygi_marshal_from_py_uint64(): Use correct data type in py2.7 check (Alban Browaeys) (#685000)
  • Install an .egg-info file (Johan Dahlin) (#680138)
  • PyGProps_getattro(): Fix GObjectClass leak (Johan Dahlin) (#685218)
  • pygobject.c: Don’t leak GObjectClass reference (Olivier Crête) (#684062)
  • Fix memory leak in _pygi_argument_to_array() (Alban Browaeys) (#685082)
  • Fix error messages for out of range numbers (Martin Pitt) (#684314)
  • Kill dbus-daemon after running tests (Martin Pitt) (#685009)
  • GVariant overrides: Support empty tuple arrays (Martin Pitt) (#684928)
  • TestGVariant: Split creation test case into several smaller ones (Martin Pitt)
  • Fix unused variables and results (Martin Pitt)
  • tests: Fix wrong return type in test_int64_callback() (Martin Pitt) (#684700)
  • Fix GValue marshalling of long and unsigned long (Giovanni Campagna) (#684331)
  • Clean up deprecation message for assigning gpointers to objects. (Simon Feltman) (#683599)
  • pygi-property: Lookup property in base classes of non-introspected types (Olivier Crête) (#684058)

Read more
mandel

Following the small work I’m doing to get better at golang here is another piece of work I have done to add a golang binding to one of the C libraries I’m depending on. The following allows to use the libaccounts-glib library from go:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
package main
 
/*
#cgo pkg-config: libaccounts-glib
#include <stdlib.h>
#include <glib.h>
#include <libaccounts-glib/accounts-glib.h>
 
static inline char* to_charptr(const gchar* s) { return (char*)s; }
 
static inline char* to_charptr_from_ptr(gpointer s) { return (char*)s; }
 
static inline gchar* to_gcharptr(const char* s) { return (gchar*)s; }
 
static inline AgService* to_AgService(void* o) { return (AgService *)o; }
 
static inline AgAccountService* to_AgAccountService(void* o) { return (AgAccountService *)o; }
 
static inline AgApplication* to_AgApplication(void* o) { return (AgApplication *)o; }
 
static inline AgProvider* to_AgProvider(void* o) { return (AgProvider *)o; }
 
static inline AgServiceType* to_AgServiceType(void* o) { return (AgServiceType *)o; }
 
static inline void free_string(char* s) { free(s); }
 
static inline AgAccountId to_AgAccountId(guint i) { return (AgAccountId) i; }
 
static inline guint to_guint(gpointer i) { return (guint)i; }
 
static GError* to_error(void* err) { return (GError*)err; }
 
extern void go_account_notify_cb(void* func, AgAccount* acc, gchar* key);
 
static void account_notify_cb(AgAccount* acc, gchar* key, gpointer func){
    go_account_notify_cb((void*)func, acc, key);
}
 
static AgAccountWatch watch_dir(AgAccount* acc, gchar* key, void* func) {
    return ag_account_watch_dir(acc, key,
        (AgAccountNotifyCb)account_notify_cb, func);
}
 
static AgAccountWatch watch_key(AgAccount* acc, gchar* key, void* func) {
    return ag_account_watch_key(acc, key,
        (AgAccountNotifyCb)account_notify_cb, func);
}
 
*/
import "C"
 
import (
    "os"
    "fmt"
    "unsafe"
    "github.com/mattn/go-gtk/gtk"
)
 
func GetStringFromGCharPtr(data *C.gchar) string {
    if data == nil {
        return ""
    }
    return C.GoString(C.to_charptr(data))
}
 
func GetServicesFromList(services *C.GList, length C.guint) ([]*Service) {
    result := make([]*Service, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(services, n)
        pointer := unsafe.Pointer(data)
        service := &Service{serv:C.to_AgService(pointer)}
        result[uint(n)] = service
    }
    return result
}
 
func GetAccountServicesFromList(services *C.GList,
    length C.guint) ([]*AccountService) {
 
    result := make([]*AccountService, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(services, n)
        pointer := unsafe.Pointer(data)
        service := &AccountService{acc:C.to_AgAccountService(pointer)}
        result[uint(n)] = service
    }
    return result
}
 
func GetIdsFromList(ids *C.GList, length C.guint) ([]uint32) {
    result := make([]uint32, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(ids, n)
        result[uint(n)] = uint32(C.to_guint(data))
    }
 
    return result
}
 
// =============================== GError =====================================
 
type Error struct {
    GError *C.GError
}
 
func (v *Error) Error() string {
    return v.Message()
}
 
func (v *Error) Message() string {
    if unsafe.Pointer(v.GError) == nil || unsafe.Pointer(v.GError.message) == nil {
        return ""
    }
    return C.GoString(C.to_charptr(v.GError.message))
}
 
func ErrorFromNative(err unsafe.Pointer) *Error {
    return &Error{C.to_error(err)}
}
 
// ============================== Application ====================================
 
type Application struct {
    app *C.AgApplication
}
 
func (app *Application) GetDescription () string {
    return GetStringFromGCharPtr(C.ag_application_get_description(app.app))
}
 
func (app *Application) GetName () string {
    return GetStringFromGCharPtr(C.ag_application_get_name(app.app))
}
 
func (app *Application) GetServiceUsage (service *Service) string {
    return GetStringFromGCharPtr(
        C.ag_application_get_service_usage(app.app, service.serv))
}
 
func (app *Application) Unref () {
    C.ag_application_unref(C.to_AgApplication(unsafe.Pointer(app.app)))
}
 
// =============================== Provider ======================================
 
type Provider struct {
    prov *C.AgProvider
}
 
func (prov *Provider) GetDisplayName () string {
    return GetStringFromGCharPtr(C.ag_provider_get_display_name(prov.prov))
}
 
func (prov *Provider) GetDescription () string {
    return GetStringFromGCharPtr(C.ag_provider_get_description(prov.prov))
}
 
func (prov *Provider) GetName () string {
    return GetStringFromGCharPtr(C.ag_provider_get_name(prov.prov))
}
 
func (prov *Provider) Unref () {
    C.ag_provider_unref(C.to_AgProvider(unsafe.Pointer(prov.prov)))
}
 
// ================================ Manager ======================================
 
type Manager struct {
    man *C.AgManager
}
 
func (man *Manager) CreateAccount (provider_name string) *Account {
    provider_str := C.CString(provider_name)
    defer C.free_string(provider_str)
 
    acc := C.ag_manager_create_account(man.man, C.to_gcharptr(provider_str))
    return &Account{acc:acc}
}
 
func (man *Manager) GetAccount (id uint32) *Account {
    acc := C.ag_manager_get_account(man.man, C.to_AgAccountId(C.guint(id)))
    return &Account{acc:acc}
}
 
func (man *Manager) GetAccountServices () ([]*AccountService, uint) {
    services := C.ag_manager_get_account_services(man.man)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := GetAccountServicesFromList(services, length)
 
    return result, uint(length)
}
 
func (man *Manager) GetApplication (app_name string) *Application {
    app_name_str := C.CString(app_name)
    defer C.free_string(app_name_str)
 
    app:= C.ag_manager_get_application(man.man, C.to_gcharptr(app_name_str))
    return &Application{app:app}
}
 
func (man *Manager) GetEnabledAccountServices() ([]*AccountService, uint) {
    services := C.ag_manager_get_enabled_account_services(man.man)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := GetAccountServicesFromList(services, length)
 
    return result, uint(length)
}
 
func (man *Manager) GetProvider(provider_name string) *Provider {
    provider_name_str := C.CString(provider_name)
    defer C.free_string(provider_name_str)
 
    provider := C.ag_manager_get_provider(man.man, C.to_gcharptr(provider_name_str))
    return &Provider{prov:provider}
}
 
func (man *Manager) GetService (service_name string) *Service {
    service_name_str := C.CString(service_name)
    defer C.free_string(service_name_str)
 
    service := C.ag_manager_get_service(man.man, C.to_gcharptr(service_name_str))
    return &Service{serv:service}
}
 
func (man *Manager) GetServiceType () string {
    return GetStringFromGCharPtr(C.ag_manager_get_service_type(man.man))
}
 
func (man *Manager) List() ([]uint32, uint) {
    account_ids := C.ag_manager_list(man.man)
    defer C.g_list_free(account_ids)
 
    length := C.g_list_length(account_ids)
    result := GetIdsFromList(account_ids, length)
 
    return result, uint(length)
}
 
func (man *Manager) ListApplicationsByService (
    service *Service) ([]*Application, uint) {
 
    apps := C.ag_manager_list_applications_by_service(
        man.man, service.serv)
    defer C.g_list_free(apps)
 
    length := C.g_list_length(apps)
    result := make([]*Application, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(apps, n)
        pointer := unsafe.Pointer(data)
        app := &Application{app:C.to_AgApplication(pointer)}
        result[uint(n)] = app
    }
 
    return result, uint(length)
}
 
func (man *Manager) ListByServiceType(
    service_type string) ([]uint32, uint) {
 
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    service_ids := C.ag_manager_list_by_service_type(
        man.man, C.to_gcharptr(service_type_str))
    defer C.g_list_free(service_ids)
 
    length := C.g_list_length(service_ids)
    result := GetIdsFromList(service_ids, length)
 
    return result, uint(length)
}
 
func (man *Manager) ListEnabled () ([]uint32, uint) {
    account_ids := C.ag_manager_list_enabled(man.man)
    defer C.g_list_free(account_ids)
 
    length := C.g_list_length(account_ids)
    result := GetIdsFromList(account_ids, length)
 
    return result, uint(length)
}
 
func (man *Manager) ListEnabledByServiceType (
    service_type string) ([]uint32, uint) {
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    account_ids := C.ag_manager_list_enabled_by_service_type(man.man,
        C.to_gcharptr(service_type_str))
 
    length := C.g_list_length(account_ids)
    result := GetIdsFromList(account_ids, length)
 
    return result, uint(length)
}
 
func (man *Manager) ListProviders () ([]*Provider, uint) {
 
    providers := C.ag_manager_list_providers(man.man)
    defer C.g_list_free(providers)
 
    length := C.g_list_length(providers)
    result := make([]*Provider, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(providers, n)
        pointer := unsafe.Pointer(data)
        app := &Provider{prov:C.to_AgProvider(pointer)}
        result[uint(n)] = app
    }
 
    return result, uint(length)
}
 
func (man *Manager) ListServiceTypes () ([]*ServiceType, uint) {
 
    services := C.ag_manager_list_service_types(man.man)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := make([]*ServiceType, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(services, n)
        pointer := unsafe.Pointer(data)
        app := &ServiceType{serv_type:C.to_AgServiceType(pointer)}
        result[uint(n)] = app
    }
 
    return result, uint(length)
}
 
func (man *Manager) ListServices () ([]*Service, uint) {
    services := C.ag_manager_list_services(man.man)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := make([]*Service, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(services, n)
        pointer := unsafe.Pointer(data)
        app := &Service{serv:C.to_AgService(pointer)}
        result[uint(n)] = app
    }
 
    return result, uint(length)
}
 
func (man *Manager) ListServicesByType (
    service_type string) ([]*Service, uint) {
 
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    services := C.ag_manager_list_services_by_type(
        man.man, C.to_gcharptr(service_type_str))
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := make([]*Service, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(services, n)
        pointer := unsafe.Pointer(data)
        app := &Service{serv:C.to_AgService(pointer)}
        result[uint(n)] = app
    }
 
    return result, uint(length)
}
 
func (man *Manager) LoadAccount (account_id uint32) (*Account, error) {
    var gerror *C.GError
 
    id := C.to_AgAccountId(C.guint(account_id))
    account := C.ag_manager_load_account(man.man, id, &gerror)
 
    if gerror != nil {
        err := ErrorFromNative(unsafe.Pointer(gerror))
        return nil, err
    }
    return &Account{acc:account}, nil
}
 
func (man *Manager) LoadServiceType (
    service_type string) *ServiceType {
 
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    stype := C.ag_manager_load_service_type(man.man,
        C.to_gcharptr(service_type_str))
    return &ServiceType{serv_type:stype}
}
 
func (man *Manager) Unref () {
    C.g_object_unref(C.gpointer(man.man))
}
 
func NewManager () *Manager {
    return &Manager{man:C.ag_manager_new()}
}
 
func NewManagerForServiceType (service_type string) *Manager {
 
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    return &Manager{man:C.ag_manager_new_for_service_type(
        C.to_gcharptr(service_type_str))}
}
 
// ============================= Account Service =================================
 
type AccountService struct {
    acc *C.AgAccountService
}
 
func (acc *AccountService) GetAccount () *Account {
    return &Account{C.ag_account_service_get_account(acc.acc)}
}
 
func (acc *AccountService) GetService () *Service {
    return &Service{C.ag_account_service_get_service(acc.acc)}
}
 
func (acc *AccountService) GetEnabled () bool {
    return C.TRUE == C.ag_account_service_get_enabled(acc.acc)
}
 
// ================================ Service ======================================
 
type Service struct {
    serv *C.AgService
}
 
func (serv *Service) GetDisplayName () string {
    return GetStringFromGCharPtr(C.ag_service_get_display_name(serv.serv))
}
 
func (serv *Service) GetName () string {
    return GetStringFromGCharPtr(C.ag_service_get_name(serv.serv))
}
 
func (serv *Service) GetDescription () string {
    return GetStringFromGCharPtr(C.ag_service_get_description(serv.serv))
}
 
func (serv *Service) GetProvider () string {
    return GetStringFromGCharPtr(C.ag_service_get_provider(serv.serv))
}
 
func (serv *Service) GetServiceType () string {
    return GetStringFromGCharPtr(C.ag_service_get_service_type(serv.serv))
}
 
func (serv *Service) GetTags () ([]string, uint) {
 
    tags := C.ag_service_get_tags(serv.serv)
    defer C.g_list_free(tags)
 
    length := C.g_list_length(tags)
    result := make([]string, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(tags, n)
        pointer := C.to_charptr_from_ptr(data)
        result[uint(n)] = C.GoString(pointer)
    }
 
    return result, uint(length)
}
 
func (serv *Service) HasTag (tag string) bool {
    tag_str := C.CString(tag)
    defer C.free_string(tag_str)
 
    has_tag := C.ag_service_has_tag(serv.serv, C.to_gcharptr(tag_str))
    return C.TRUE == has_tag
}
 
func (serv *Service) Unref () {
    C.ag_service_unref(C.to_AgService(unsafe.Pointer(serv.serv)))
}
 
// ============================== ServiceType ====================================
 
type ServiceType struct {
    serv_type *C.AgServiceType
}
 
func (serv *ServiceType) GetDisplayName () string {
    return GetStringFromGCharPtr(
        C.ag_service_type_get_display_name(serv.serv_type))
}
 
func (serv *ServiceType) GetDescription () string {
    return GetStringFromGCharPtr(
        C.ag_service_type_get_description(serv.serv_type))
}
 
func (serv *ServiceType) GetName () string {
    return GetStringFromGCharPtr(C.ag_service_type_get_name(serv.serv_type))
}
 
func (serv *ServiceType) GetTags () ([]string, uint) {
 
    tags := C.ag_service_get_tags(serv.serv_type)
    defer C.g_list_free(tags)
 
    length := C.g_list_length(tags)
    result := make([]string, length)
 
    for n := C.guint(0); n < length; n++ {
        data := C.g_list_nth_data(tags, n)
        pointer := C.to_charptr_from_ptr(data)
        result[uint(n)] = C.GoString(pointer)
    }
 
    return result, uint(length)
}
 
func (serv *ServiceType) HasTag (tag string) bool {
    tag_str := C.CString(tag)
    defer C.free_string(tag_str)
 
    has_tag := C.ag_service_has_tag(serv.serv_type, C.to_gcharptr(tag_str))
    return C.TRUE == has_tag
}
 
func (serv *ServiceType) Unref () {
    C.ag_service_type_unref(C.to_AgServiceType(
        unsafe.Pointer(serv.serv_type)))
}
 
// ============================== Account Watch ==================================
 
type AccountWatch struct {
    watch *C.AgAccountWatch
}
 
func (watch *AccountWatch ) Unref () {
    C.g_object_unref(C.gpointer(watch.watch))
}
 
// ================================ Account ======================================
 
type AccountAsyncStoreCallback func(acc *Account, success bool, err error)
 
type AccountAsyncWatchDirCallback func(acc *Account, key string)
 
type Account struct {
    acc *C.AgAccount
}
 
//export go_account_notify_cb
func go_account_notify_cb(pcallback unsafe.Pointer, gaccount *C.AgAccount,
    gkey *C.gchar) {
 
    account := &Account{acc:gaccount}
    key := C.GoString(C.to_charptr(gkey))
    callback := *(*func(*Account, string))(pcallback)
    callback(account, key)
}
 
func (acc *Account) Delete () {
    C.ag_account_delete(acc.acc)
}
 
func (acc *Account) GetDisplayName () string {
    return GetStringFromGCharPtr(C.ag_account_get_display_name(acc.acc))
}
 
func (acc *Account) GetEnabled () bool {
    return C.TRUE == C.ag_account_get_enabled(acc.acc)
}
 
func (acc *Account) GetManager () *Manager {
    return &Manager{man:C.ag_account_get_manager(acc.acc)}
}
 
func (acc *Account) GetProviderName () string {
    return GetStringFromGCharPtr(C.ag_account_get_provider_name(acc.acc))
}
 
func (acc *Account) GetSelectedService () *Service {
   return &Service{serv:C.ag_account_get_selected_service(acc.acc)}
}
 
func (acc *Account) ListEnabledServices () ([]*Service, uint) {
    services := C.ag_account_list_enabled_services(acc.acc)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := GetServicesFromList(services, length)
 
    return result, uint(length)
}
 
func (acc *Account) ListServices () ([]*Service, uint) {
    services := C.ag_account_list_services(acc.acc)
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := GetServicesFromList(services, length)
 
    return result, uint(length)
}
 
func (acc *Account) ListServicesByType (service_type string) ([]*Service, uint) {
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    services := C.ag_account_list_services_by_type(acc.acc,
        C.to_gcharptr(service_type_str))
    defer C.g_list_free(services)
 
    length := C.g_list_length(services)
    result := GetServicesFromList(services, length)
 
    return result, uint(length)
}
 
func (acc *Account) RemoveWatch (watch *AccountWatch) {
    C.ag_account_remove_watch(acc.acc, *watch.watch)
}
 
func (acc *Account) SelectService (service *Service) {
    C.ag_account_select_service(acc.acc, service.serv)
}
 
func (acc *Account) SetDisplayName (name string) {
    name_str := C.CString(name)
    defer C.free_string(name_str)
    C.ag_account_set_display_name(acc.acc, C.to_gcharptr(name_str))
}
 
func (acc *Account) SetEnabled (enabled bool) {
    if enabled {
        C.ag_account_set_enabled(acc.acc, C.TRUE)
    } else {
        C.ag_account_set_enabled(acc.acc, C.FALSE)
    }
}
 
func (acc *Account) Sign (key string, token string) {
    key_str := C.CString(key)
    defer C.free_string(key_str)
 
    token_str := C.CString(token)
    defer C.free_string(token_str)
 
    C.ag_account_sign(acc.acc, C.to_gcharptr(key_str), C.to_gcharptr(token_str))
}
 
func (acc *Account) Store (callback AccountAsyncStoreCallback) {
 
    go func(){
        var gerror *C.GError
        C.ag_account_store_blocking(acc.acc, &gerror)
        if gerror != nil {
            err := ErrorFromNative(unsafe.Pointer(gerror))
            callback(acc, false, err)
            return
        }
        callback(acc, true, nil)
    }()
}
 
func (acc *Account) StoreSync () (bool, error){
    var gerror *C.GError
    C.ag_account_store_blocking(acc.acc, &gerror)
    if gerror != nil {
        err := ErrorFromNative(unsafe.Pointer(gerror))
        return false, err
    }
    return true, nil
}
 
func (acc *Account) SupportsService (service_type string) bool {
    service_type_str := C.CString(service_type)
    defer C.free_string(service_type_str)
 
    suported := C.ag_account_supports_service(acc.acc,
        C.to_gcharptr(service_type_str))
    return suported == C.TRUE
}
 
func (acc *Account) Verify (key string) (bool, string) {
    key_str := C.CString(key)
    defer C.free_string(key_str)
 
    var token *C.gchar
    verified := C.ag_account_verify(acc.acc, C.to_gcharptr(key_str), &token)
 
    return verified == C.TRUE, C.GoString(C.to_charptr(token))
}
 
func (acc *Account) VerifyWithTokens (key string, tokens []string) bool {
    key_str := C.CString(key)
    defer C.free_string(key_str)
 
    tokens_str := make([]*C.gchar, len(tokens))
    for n := 0; n < len(tokens); n++ {
        token := C.CString(tokens[n])
        defer C.free_string(token)
 
        tokens_str[n] = C.to_gcharptr(token)
    }
 
    verified := C.ag_account_verify_with_tokens(acc.acc, C.to_gcharptr(key_str),
        &tokens_str[0])
    return verified == C.TRUE
}
 
func (acc *Account) WatchDir (key string,
    callback AccountAsyncWatchDirCallback) *AccountWatch {
 
    key_str := C.CString(key)
    defer C.free_string(key_str)
 
    watch := C.watch_dir(acc.acc, C.to_gcharptr(key_str), unsafe.Pointer(&callback))
    return &AccountWatch{watch:&watch}
}
 
func (acc *Account) WatchKey (key string,
    callback AccountAsyncWatchDirCallback) *AccountWatch {
 
    key_str := C.CString(key)
    defer C.free_string(key_str)
 
    watch := C.watch_key(acc.acc, C.to_gcharptr(key_str), unsafe.Pointer(&callback))
    return &AccountWatch{watch:&watch}
}
 
func (acc *Account) Unref () {
    C.g_object_unref(C.gpointer(acc.acc))
}
 
func main() {
    fmt.Println("test")
    gtk.Init(&os.Args)
    go func () {
        manager := NewManagerForServiceType("microblogging")
        defer manager.Unref()
        services, length := manager.GetAccountServices()
        fmt.Printf("Got %d servicesn", length)
        for n := uint(0); n < length; n++ {
            s := services[n].GetService()
            fmt.Printf("Display Name: %sn", s.GetDisplayName())
            fmt.Printf("Name: %sn", s.GetName())
            fmt.Printf("Description: %sn", s.GetDescription())
            fmt.Printf("Provider: %sn", s.GetProvider())
        }
        gtk.MainQuit()
    }()
    gtk.Main()
}

By the way I have fixed a small mem leak I had int he goa bindings by adding the Unref methods so that the glib structures can be freed once you are done with them.

Read more
pitti

I was working on writing tests for gnome-settings-daemon a week or so ago, and finally got blocked on being unable to set up upower/ConsoleKit/etc. the way I need them. Also, doing so needs root privileges, I don’t want my test suite to actually suspend my machine, and using the real service is generally not suitable for test suites that are supposed to run during “make check”, in jhbuild, and the like — these do not have the polkit privileges to do all that, and may not even have a system D-Bus running in the first place.

So I wrote a little test_upower.py helper, then realized that I need another one for systemd/ConsoleKit (for the “system idle” property), also looked at the mock polkit in udisks and finally sat down for two days to generalize this and do this properly.

The result is python-dbusmock, I just released the first tarball. With this you can easily create mock objects on D-Bus from any programming language with a D-Bus binding, or even from the shell.

The mock objects look like the real API (or at least the parts that you actually need), but they do not actually do anything (or only some action that you specify yourself). You can configure their state, behaviour and responses as you like in your test, without making any assumptions about the real system status.

When using a local system/session bus, you can do unit or integration testing without needing root privileges or disturbing a running system. The Python API offers some convenience functions like “start_session_bus()“ and “start_system_bus()“ for this, in a “DBusTestCase“ class (subclass of the standard “unittest.TestCase“).

Surprisingly I found very little precedence here. There is a Perl module, but that’s not particuarly helpful for test suites in C/Vala/Python. And there is Phil’s excellent Bendy Bus, but this has a different goal: If you want to thoroughly test a particular D-BUS service, such as ensuring that it does the right thing, doesn’t crash on bad input, etc., then Bendy Bus is for you (and python-dbusmock isn’t). However, it is too much overhead and rather inconvenient if you want to test a client-side program and just need a few system services around it which you want to set up in different states for each test.

You can use python-dbusmock with any programming language, as you can run the mocker as a normal program. The actual setup of the mock (adding objects, methods, properties, etc.) all happen via D-Bus methods on the “org.freedesktop.DBus.Mock“ interface. You just don’t have the convenience D-Bus launch API.

The simplest possible example is to create a mock upower with a single Suspend() method, which you can set up like this from Python:

import dbus
import dbusmock

class TestMyProgram(dbusmock.DBusTestCase):
[...]
    def setUp(self):
        self.p_mock = self.spawn_server('org.freedesktop.UPower',
                                        '/org/freedesktop/UPower',
                                        'org.freedesktop.UPower',
                                        system_bus=True,
                                        stdout=subprocess.PIPE)

        # Get a proxy for the UPower object's Mock interface
        self.dbus_upower_mock = dbus.Interface(self.dbus_con.get_object(
            'org.freedesktop.UPower', '/org/freedesktop/UPower'),
            'org.freedesktop.DBus.Mock')

        self.dbus_upower_mock.AddMethod('', 'Suspend', '', '', '')

[...]

    def test_suspend_on_idle(self):
        # run your program in a way that should trigger one suspend call

        # now check the log that we got one Suspend() call
        self.assertRegex(self.p_mock.stdout.readline(), b'^[0-9.]+ Suspend$')

This doesn’t depend on Python, you can just as well run the mocker like this:

python3 -m dbusmock org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower

and then set up the mocks through D-Bus like

gdbus call --system -d org.freedesktop.UPower -o /org/freedesktop/UPower \
      -m org.freedesktop.DBus.Mock.AddMethod '' Suspend '' '' ''

If you use it with Python, you get access to the dbusmock.DBusTestCase class which provides some convenience functions to set up and tear down local private session and system buses. If you use it from another language, you have to call dbus-launch yourself.

Please see the README for some more details, pointers to documentation and examples.

Update: You can now install this via pip from PyPI or from the daily builds PPA.

Update 2: Adjusted blog entry for version 0.0.3 API, to avoid spreading now false information too far.

Read more
pitti

I just released PyGObject 3.3.92, for GNOME 3.5.92.

There is nothing too exciting in this release; a couple of small bug fixes and a lot of new test cases. See the detailled list of changes below.

Thanks to all contributors!

Changes:

  • release-news: Generate HTML changelog (Martin Pitt)
  • [API add] Add ObjectInfo.get_abstract method (Simon Feltman) (#675581)
  • Add deprecation warning when setting gpointers to anything other than int. (Simon Feltman) (#683599)
  • test_properties: Test accessing a property from a superclass (Martin Pitt) (#684058)
  • test_properties.py: Consistent test names (Martin Pitt)
  • test_everything: Ensure TestSignals callback does get called (Martin Pitt)
  • argument: Fix 64bit integer convertion from GValue (Nicolas Dufresne) (#683596)
  • Add Simon Feltman as a project maintainer (Martin Pitt)
  • test_signals.py: Drop global type variables (Martin Pitt)
  • test_signals.py: Consistent test names (Martin Pitt)
  • Add test cases for GValue signal arguments (Martin Pitt) (#683775)
  • Add test for GValue signal return values (Martin Pitt) (#683596)
  • Improve setting pointer fields/arguments to NULL using None (Simon Feltman) (#683150)
  • Test gint64 C signal arguments and return values (Martin Pitt)
  • Test in/out int64 GValue method arguments. (Martin Pitt) (#683596)
  • Bump g-i dependency to 1.33.10 (Martin Pitt)
  • Fix -uninstalled.pc.in file (Thibault Saunier) (#683379)

Read more
pitti

I just released PyGObject 3.3.90, for GNOME 3.5.90.

This is now working correctly on big-endian 64 bit machines such as powerpc64, and fixes marshalling for GParamSpec attributes and return values, as well as a few small bug fixes.

Thanks to all contributors!

Complete list of changes:

  • Implement marshalling for GParamSpec (Mathieu Duponchelle) (#681565)
  • Fix erronous import statements for Python 3.3 (Simon Feltman) (#682051)
  • Do not fail tests if pyflakes or pep8 are not installed (Martin Pitt)
  • Fix PEP-8 whitespace checking and issues in the code (Martin Pitt)
  • Fix unmarshalling of gssize (David Malcolm) (#680693)
  • Fix various endianess errors (David Malcolm) (#680692)
  • Gtk overrides: Add TreeModelSort.__init__(self, model) (Simon Feltman) (#681477)
  • Convert Gtk.CellRendererState in the pygi-convert script (Manuel Quiñones) (#681596)

Read more
pitti

Yesterday, GUADEC hosted a PyGObject hackfest. I was really happy to see so many participants, and a lot of whom who are rather new to the project. I originally feared that it would just be the core crew of four people, as this is not exactly the shiniest part of GNOME development.

So I did not work on the stuff I was planning for, but instead walked around and provided mentoring, help, and patch review. Unfortunately I do not know all the results from the participants, hopefully they will blog some details themselves. But this is what I was involved in:

  • Manuel Quiñones added an gtk_tree_view_column_set_attributes() override (the original C function uses varargs and thus is not introspectable). Most time was spent figuring out an appropriate test case.
  • I showed Didier Roche some tricks about porting a pygtk application to PyGI/GTK3. He gave a shot to porting Meld, but unfortunately it uses a lot of pygtk hacks/tricks, most of which are obsolete now. So this proved too big a project for one day eventually :-(
  • Paolo and I guided Marta Maria Casetti, one of this year’s GNOME GSoC students, through her first pygobject patch. The test case still needs some love (again, nothing regarding GtkTreeView is easy), but the actual patch is good. Thanks Marta for participating, and not getting intimidated by all the new stuff!
  • While working on above patch, Marta encountered a rather curious TypeError: Expected Gtk.TreeViewColumn, but got GObjectMeta when writing the override. What seemed to be a trivial problem at first quickly turned into an one-hour debugging session involving grandmaster John Palmieri and me, with others chipping in as well. In the end it (of course!) turned out to be a trivial four-character change in Marta’s patch, but it was fun to get to understand the problem (a loong-forgotten special case of overrides resolution in overrides code). Now pygobject gives a proper error message which is actually helpful, i. e. which argument causes the problem and which module/class/method is provided, which should prevent us from being misguided into the totally wrong direction the next time this happens.
  • John Stowers got the Windows build working again, and showed off the gtk-demo under Windows. This is really amazing, I hope we can get that into trunk soon and not let it bitrot again for so long. Thanks!
  • Simon and Manuel worked on porting some Sugar extensions. Together with Paolo we also discussed the GStreamer 1.0 API a bit, which parts can become API additions and which need to become overrides.
  • Michal Hruby debugged a leak in the handling of GVariant arrays when using libdee.

Thanks everyone for participating! I hope everyone enjoyed it and got to learn a new thing or two. See you at the next one!

PyGObject hackfest at GUADEC 2012

PyGObject hackfest at GUADEC 2012

Read more
pitti

I have had the pleasure of attending GUADEC in full this year. TL;DR: A lot of great presentations + lots of hall conversations about QA stuff + the obligatory be{er,ach} = ?.

Last year I just went to the hackfest, and I never made it to any previous one, so GUADEC 2012 was a kind of first-time experience for me. It was great to put some faces and personal impressions to a lot of the people I have worked with for many years, as well as catching up with others that I did meet before.

I discussed various hardware/software testing stuff with Colin Walters, Matthias Clasen, Lennart Poettering, Bertrand Lorentz, and others, so I have a better idea how to proceed with automated testing in plumbing and GNOME now. It was also really nice to meet my fellow PyGObject co-maintainer Paolo Borelli, as well as seeing Simon Schampier and Ignacio Casal Quinteiro again.

No need to replicate the whole schedule here (see for yourself on the interwebs), so I just want to point out some personal highlights in the presentations:

  • Jacob Appelbaum’s keynote about Tor brought up some surprising facts about how the project has outgrown its past performance problems and how useful it was during e. g. the Arab revolution
  • .

  • Philip Whitnall’s presented Bendy Bus, a tool to mock D-Bus services for both unit and fuzz testing. He successfully used it to find and replicate bugs in Evolution (by mocking evolution-data-server) as well as libfolks (by mocking the telepathy daemons). It should work just as well to mock system services like upower or NetworkManager to test the UI bits that use it. This is a topic which has been on my wishlist for a long time already, so I’m happy that there is already an existing solution out there. We might have to add some small features to it, but it’s by and large what I had in mind, and in the discussion afterwards Philip said he’d appreciate patches against it.
  • Christophe Fergeau showed how to easily do Windows builds and installers from GNOME tarballs with MinGW-w64, without having to actually touch/use Windows (using cross-building and running tests etc. under wine). I found it surprising how easy that actually is, and it should not be hard to integrate that in a jhbuild-like setup, so that it does not keep breaking every time.
  • Colin Walters gave an introduction to OSTree, a project to build bootable images from kernel/plumbing/desktop upstream git heads on a daily basis. This is mostly to avoid the long delays that we otherwise have with doing upstream releases, packaging them, and getting them into a form that can safely be tested by users. In an afterwards discussion we threw some ideas around how we can integrate existing and future tests into this (something in spirit like our autopkgtest). This will be the area where I’ll put most focus on in the next time.
  • Adam Dingle of yorba fame shared his thoughts about how we can crowdfunding of Free Software Projects work in practice, comparing efforts like codefoundry and kickstarter. Of course he does not have a solution for this yet, but he raised some interesting concerns and it spun off lots of good discussions over lunchtime.
  • Last but not least, the sport event on Saturday evening was awesome! In hindsight I was happy to not have signed up for soccer, as people like Bastian or Jordi played this really seriously. I participated in the Basketball competition instead, which was the right mix of fun and competition without seriously trying to hurt each other. :-)

There were a lot of other good ones, some of them technical and some amusing and enlightening, such as Frederico’s review of the history of GNOME.

On Monday I prepared and participated in a PyGObject hackfest, but I’ll blog about this separately.

I want to thank all presenters for the excellent program, as well as the tireless GUADEC organizer team for making everything so smooth and working flawlessly! Great Job, and see you again in Strasbourg or Brno!

Read more
pitti

I started to collect some easy PyGObject bugs which are appropriate for the PyGObject hackfest at GUADEC on July 30th. These are bugs which do not need a lot of previous knowlege and are excellent starters for new contributors, such as adding overrides, fixing build system issues, etc.

I also created an initial idea pool/agenda/coordination page, where participants can add or signup for things to work on.

Feel free to add your own topics! I’m really looking forward to GUADEC and the hackfest, see you there!

GUADEC 2012

Read more
pitti

I released PyGObject 3.3.4. This is mostly a bug fix only release to fix existing API. Highlights are that lists of GVariants and other corner cases are now working correctly when being passed from C to Python, and that calling help() on a GI module now does something sensible.

Thanks to all contributors!

Complete list of changes:

  • pygi-convert.sh: Drop bogus filter_new() conversion (Martin Pitt) (#679999)
  • Fix help() for GI modules (Martin Pitt) (#679804)
  • Skip gi.CallbackInfo objects from a module’s dir() (Martin Pitt) (#679804)
  • Fix __path__ module attribute (Martin Pitt)
  • pygi-convert.sh: Fix some child ? getChild() false positives (Joe R. Nassimian) (#680004)
  • Fix array handling for interfaces, properties, and signals (Mikkel Kamstrup Erlandsen) (#667244)
  • Add conversion of the Gdk.PropMode constants to pygi-convert.sh script (Manuel Quiñones) (#679775)
  • Add the same rules for pack_start to convert pack_end (Manuel Quiñones) (#679760)
  • Add error-checking for the case where _arg_cache_new() fails (Dave Malcolm) (#678914)
  • Add conversion of the Gdk.NotifyType constants to pygi-convert.sh script (Manuel Quiñones) (#679754)
  • Fix PyObject_Repr and PyObject_Str reference leaks (Simon Feltman) (#675857)
  • [API add] Gtk overrides: Add TreePath.__len__() (Martin Pitt) (#679199)
  • GLib.Variant: Fix repr(), add proper str() (Martin Pitt) (#679336)
  • m4/python.m4: Update Python version list (Martin Pitt)
  • Remove “label” property from Gtk.MenuItem if it is not set (Micah Carrick) (#670575)

Read more
pitti

I just received confirmation that my request for a PyGObject hackfest has been approved by the GUADEC organizers.

If you are developing GObject-introspection based Python applications and have some problems with PyGObject, this is the time and place to get to know each other, getting bugs fixed, learn about pygobject’s innards, or update libraries to become introspectable. I will prepare a list of easy things to look into if you are interested in learning about and getting involved in PyGObject’s development.

See you on July 30th in A Coruña!

GUADEC Badge

Read more
pitti

I released PyGObject 3.3.3.

The most notable changes are that you can now access methods (and other identifiers) which are Python keywords, PyGObject automatically escapes them now by appending a ‘_’. For example, you can now call myGdkWindow.raise_() or GLib.Thread.yield_() instead of having to resort to the previous workaround getattr(myGdkWindow, 'raise')().

This version also restores the deprecated get_data() and set_data() methods. They were never really meant to be used from Python programs, they can potentially mess up your program and cause crashes, and do not give you anything that regular Python object properties would not already provide in a much safer way (i. e. just write my_obj.foo = 'bar' instead of my_obj.set_data('foo', 'bar')). Apparently some software projects are using them, so they will now raise a deprecation warning and be removed for the GNOME 3.8 cycle instead.

Thanks to all contributors!

Complete list of changes:

  • Remove obsolete release-tag make target (Martin Pitt)
  • Do not do any python calls when GObjects are destroyed after the python interpreter has been finalized (Simon Schampijer) (#678046)
  • Do not change constructor-only “type” Window property (Martin Pitt) (#678510)
  • Escape identifiers which are Python keywords (Martin Pitt) (#676746)
  • Fix code for PEP-8 violations detected by the latest pep8 checker. (Martin Pitt)
  • Fix crash in GLib.find_program_in_path() (Martin Pitt) (#678119)
  • Revert “Do not bind gobject_get_data() and gobject_set_data()” (Martin Pitt) (#641944)
  • GVariant: Raise proper TypeError on invalid tuple input (David Keijser) (#678317)

Update:Just released 3.3.3.1 to fix a regresssion from the keyword escaping patch. It also escaped enum and flags names, but as they are translated to upper case they are never keywords.

Read more
pitti

I just released PyGObject 3.3.2, (almost) in time for tomorrow’s GNOME 3.5.2 release. No API breaks or new features this time, just lots of bug fixes and some minor API completions. My personal favorite is making closure calls work with GVariant arguments, which I finally figured out after over half a year; this finally unblocks making GDBus fully introspectable with not too much additional work, only that in the meantime dbus-python was ported to Python 3 so that the need for it is actually a lot smaller now.

Thanks to all contributors!

Complete list of changes:

  • foreign: Register cairo.Path and cairo.FontOptions foreign structs (Bastian Winkler) (#677388)
  • Check types in GBoxed assignments (Marien Zwart) (#676603)
  • [API add] Gtk overrides: Add TreeModelRow.get_previous() (Bastian Winkler) (#677389)
  • [API add] Add missing GObject.TYPE_VARIANT (Bastian Winkler) (#677387)
  • Fix boxed type equality (Jasper St. Pierre) (#677249)
  • Fix TestProperties.testBoxed test (Jose Rostagno) (#676644)
  • Fix handling of by-reference structs as out parameters (Carlos Garnacho) (#653151)
  • tests: Add more vfunc checks for GIMarshallingTestsObject (Martin Pitt)
  • Test caller-allocated GValue out parameter (Martin Pitt) (#653151)
  • GObject.bind_property: Support transform functions (Bastian Winkler) (#676169)
  • Fix lookup of vfuncs in parent classes (Carlos Garnacho) (#672864)
  • tests/test_properties.py: Fix whitespace (Martin Pitt)
  • gi: Support zero-terminated arrays with length arguments (Jasper St. Pierre) (#677124)
  • [API add] Add GObject.bind_property method (Simon Feltman) (#675582)
  • pygtkcompat: Correctly set flags (Jose Rostagno) (#675911)
  • Gtk overrides: Implement __delitem__ on TreeModel (Jose Rostagno) (#675892)
  • Gdk Color override should support red/green/blue_float properties (Simon Feltman) (#675579)
  • Support marshalling of GVariants for closures (Martin Pitt) (#656554)
  • _pygi_argument_from_object(): Check for compatible data type (Martin Pitt)
  • pygtkcompat: Fix color conversion (Martin Pitt)
  • test_gi: Check setting properties in constructor (Martin Pitt)
  • Support getting and setting GStrv properties (Martin Pitt)
  • Support defining GStrv properties from Python (Martin Pitt)
  • Add GObject.TYPE_STRV constant (Martin Pitt)
  • Unref GVariants when destroying the wrapper (Martin Pitt) (#675472)
  • Fix TestArrayGVariant test cases (Martin Pitt)
  • pygtkcompat: Add gdk.pixbuf_get_formats compat code (Jose Rostagno) (#675489)
  • pygtkcompat: Add some more compat functions (Jose Rostagno) (#675489)
  • Fix tests for Python 3 (Martin Pitt)
  • Fix building with –disable-cairo (Martin Pitt)
  • tests: Fix deprecated assertions (Martin Pitt)
  • Run tests with MALLOC_PERTURB_ (Martin Pitt)

Read more
pitti

As I wrote two weeks ago, I consider the QA related changes in Ubuntu 12.04 a great success. But while we will continue and even extend our efforts there, this is not where the ball stops: it’s great to have the feedback cycle between “break it” and “notice the bug” reduced from potentially a few months to one day in many cases, but wouldn’t it be cool to reduce that to a few minutes, and also put the machinery right at where stuff really happens — into the upstream trunks? If for every commit to PyGObject, GTK, NetworkManager, udisks, D-BUS, telepathy, gvfs, etc. we’d immediately build and test all reverse dependencies and the committer would be told about regressions?

I have had the desire to work on automated tests in Linux Plumbing and GNOME for quite a while now. Also, after 8 years of doing distribution work of packaging and processes (tech lead, release engineering/management, stable release updates, etc.) I wanted to shift my focus towards technology development. So I’ve been looking for a new role for some time now.

It seems that time is finally there: At the recent UDS, Mark announced that we will extend our QA efforts to upstream. I am very happy that in two weeks I can now move into a role to make this happen: Developing technology to make testing easier, work with our key upstreams to set up test suites and reporting, and I also can do some general development in areas that are near and dear to my heart, like udev/systemd, udisks, pygobject, etc. This work will be following the upstream conventions for infrastructure and development policies. In particular, it is not bound by Canonical copyright license agreements.

I have a bunch of random ideas what to work on, such as:

  • Making it possible/easier to write tests with fake hardware. E. g. in the upower integration tests that I wrote a while ago there is some code to create a fake sysfs tree which should really go into udev itself, available from C and introspection and be greatly extended. Also, it’s currently not possible to simulate a uevent that way, that’s something I’d like to add. Right now you can only set up /sys, start your daemon, and check the state after the coldplugging phase.
  • Interview some GNOME developers what kind of bugs/regressions/code they have most trouble with and what/how they would like to test. Then write a test suite with a few working and one non-working case (bugzilla should help with finding these), discuss the structure with the maintainer again, find some ways to make the tests radically simpler by adding/enhancing the API available from gudev/glib/gtk, etc. E. g. in the tests for apport-gtk I noticed that while it’s possible to do automatic testing of GUI applications it is still way harder than it should and needs to be. I guess that’s the main reason why there are hardly any GUI tests in GNOME?
  • I’ve heard from several people that it would be nice to be able to generate some mock wifi/ethernet/modem adapters to be able to automatically test NetworkManager and the like. As network devices are handled specially in Linux, not in the usual /dev and sysfs manner, they are not easy to fake. It probably needs a kernel module similar to scsi_debug, which fakes enough of the properties and behaviour of particular nmetwork card devices to be useful for testing. One could certainly provide a pipe or a regular bridge device at the other end to actually talk to the application through the fake device. (NB this is just an idea, I haven’t looked into details at all yet).
  • For some GUI tests it would be much easier if there was a very simple way of providing mocks/stubs for D-BUS services like udisks or NetworkManager than having to set up the actual daemons, coerce them into some corner-case behaviour, and needing root privileges for the test due to that. There seems to be some prior art in Ruby, but I’d really like to see this in D-BUS itself (perhaps a new library there?), and/or having this in GDBus where it would even be useful for Python or JavaScript tests through gobject-introspection.
  • There are nice tools like the Clang static code analyzer out there. I’d like to play with those and see how we can use it without generating a lot of false positives.
  • Robustify jhbuild to be able to keep up with building everything largely unattended. Right now you need to blow away and rebuild your tree way too often, due to brittle autotools or undeclared dependencies, and if we want to run this automatically in Jenkins it needs to be able to recover by itself. It should be able to keep up with the daily development, automatically starting build/test jobs for all reverse dependencies for a module that just has changed (and for basic libraries like GLib or GTK that’s going to be a lot), and perhaps send out mail notifications when a commit breaks something else. This also needs some discussion first, about how/where to do the notifications, etc.

Other ideas will emerge, and I hope lots of you have their own ideas what we can do. So please talk to me! We’ll also look for a second person to work in that area, so that we have some capacity and also the possibility to bounce ideas and code reviews between each other.

Read more
pitti

This announcement comes very late (a week after release), but better late than never..

The first PyGObject 3.3 series release is now out, with lots of yummy fixes and improvements. Dieter, Sebastian, and I went through a round of bugzilla spring cleaning to clean up old bugs, fix simple bugs, and apply good patches that were waiting, so as a result the patch queue is now almost empty and PyGObject works better than ever.

There was also quite some work on the test suite: it became a lot stricter and robust, and now also enforces PEP8 compatibility and absence of pyflake errors of the code.

One small but handy new feature is that the freeze_notify() and handler_block() methods are now context managers, i. e. they automatically call the corresponding thaw_notify()/handler_unblock() at the end of the with statement in an exception-safe way. ((#672324)

There are almost no API changes in this release, so it should work fine with GNOME 3.4 and applications developed with pygobject 3.2. The one exception is the removal of the Gobject.get_data() and Gobject.set_data() methods. They were prone to errors and crashes as they are not safely bindable, and in Python you can and should just use normal Python object attributes instead.

Complete list of changes:

  • GSettings: allow extra keyword arguments (Giovanni Campagna) (#675105)
  • pygtkcompat: Correct Userlist module use (Jose Rostagno) (#675084)
  • Add release-news make rule (Martin Pitt)
  • Add “make check.nemiver” target (Martin Pitt)
  • Test flags and enums in GHash values (Martin Pitt) (#637466)
  • tests: Activate test_hash_in and apply workaround (Martin Pitt) (#666636)
  • Add special case for Gdk.Atom array entries from Python (Martin Pitt) (#661709)
  • test_gdbus: Call GetConnectionUnixProcessID() with correct signature (Martin Pitt) (#667954)
  • Add test case for Gtk.ListStore custom sort (Martin Pitt) (#674475)
  • GTK overrides: Add missing keyword arguments (Martin Pitt) (#660018)
  • Add missing override for TreeModel.iter_previous() (Martin Pitt) (#660018)
  • pygi-convert.py: Drop obsolete drag method conversions (Martin Pitt) (#652860)
  • tests: Replace deprecated assertEquals() with assertEqual() (Martin Pitt)
  • Plug tiny leak in constant_info_get_value (Paolo Borelli) (#642754)
  • Fix len_arg_index for array arguments (Bastian Winkler) (#674271)
  • Support defining GType properties from Python (Martin Pitt) (#674351)
  • Handle GType properties correctly (Bastian Winkler) (#674351)
  • Add missing GObject.TYPE_GTYPE (Martin Pitt)
  • Fix test_mainloop.py for Python 3 (Martin Pitt)
  • Make callback exception propagation test stricter (Martin Pitt) (#616279)
  • Add context management to freeze_notify() and handler_block(). (Simon Feltman) (#672324)
  • Add support for GFlags properties (Martin Pitt) (#620943)
  • Wrap GLib.Source.is_destroyed() method (Martin Pitt) (#524719)
  • Fix error message when trying to override a non-GI class (Martin Pitt) (#646667)
  • Fix segfault when accessing __grefcount__ before creating the GObject (Steve Frécinaux) (#640434)
  • Do not bind gobject_get_data() and gobject_set_data() (Steve Frécinaux) (#641944)
  • Add test case for multiple GLib.MainLoop instances (Martin Pitt) (#663068)
  • Add a ccallback type which is used to invoke callbacks passed to a vfunc (John (J5) Palmieri) (#644926)
  • Regression test: marshalling GValues in GHashTable (Alberto Mardegan) (#668903)
  • Update .gitignore (Martin Pitt)
  • Fix “distcheck” and tests with out-of-tree builds (Martin Pitt)
  • Add a pep8 check to the makefile (Johan Dahlin) (#672627)
  • PEP8 whitespace fixes (Johan Dahlin) (#672627)
  • PEP8: Remove trailing ; (Johan Dahlin) (#672627)
  • tests: Replace deprecated Python API (Martin Pitt)
  • Fail tests if they use or encounter deprecations (Martin Pitt)
  • Do not run tests in two phases any more (Martin Pitt)
  • test_overrides: Find local gsettings schema with current glib (Martin Pitt)
  • Add GtkComboBoxEntry compatibility (Paolo Borelli) (#672589)
  • Correct review comments from Martin (Johan Dahlin) (#672578)
  • Correct pyflakes warnings/errors (Johan Dahlin) (#672578)
  • Make tests fail on CRITICAL logs, too, and apply to all tests (Martin Pitt)
  • Support marshalling GI_TYPE_TAG_INTERFACE (Alberto Mardegan) (#668903)
  • Fix warnings on None values in added tree/list store rows (Martin Pitt) (#672463)
  • pygtkcompat test: Properly clean up PixbufLoader (Martin Pitt)

Read more
pitti

I just released a new pygobject version 3.1.92, for this week’s GNOME 3.3.92. This was my first-ever GNOME release (yay!), so please bear with me.

One highlight of this release is the new pygtkcompat module, contributed by Johan Dahlin. It provides backwards compatibility to pygtk far beyond to what the Gtk overrrides do, and also includes some shims for the old static webkit, gudev, and other modules. You can, and have to, enable them individually:

import gi.pygtkcompat

# enable "gobject" and "glib" modules
gi.pygtkcompat.enable()
gi.pygtkcompat.enable_gtk(version='3.0')

import glib
import gtk

Now you can use gtk.Window(), glib.timeout_add() etc. as before, and these will be transparently be converted into their modern GI counterparts. Please note that this is still in its infancy, and also mostly meant to ease the porting to GI. It’s not something we’ll keep forever.

Thanks to Michel Dänzer this release now also works properly on big-endian machines.

I mostly worked on fixing the calls of methods which take a list of GValues as arguments, such as Gtk.ListStore.insert_with_valuesv() and similar functions, and made the override API for tree models (append() etc. with providing row data) atomic wrt. the signals it sends out.

I want to thank Johan and Paolo for the nice teamwork with reviewing each other’s patches. That’s open source at its best!

Complete list of changes:

  • Correct Gtk.TreePath.__iter__ to work with Python 3 (Johan Dahlin)
  • Fix test_everything.TestSignals.test_object_param_signal test case (Martin Pitt)
  • Add a PyGTK compatibility layer (Johan Dahlin)
  • pygtkcompat: Remove first argument for get_origin() (Johan Dahlin)
  • Fix pygtkcompat.py to work with Python 3 (Martin Pitt)
  • GtkViewport: Add a default values for the adjustment constructor parameters (Johan Dahlin)
  • GtkIconSet: Add a default value for the pixbuf constructor parameter (Johan Dahlin)
  • PangoLayout: Add a default value for set_markup() (Johan Dahlin)
  • Gtk[HV]Scrollbar: Add a default value for the adjustment constructor parameter (Johan Dahlin)
  • GtkToolButton: Add a default value for the stock_id constructor parameter (Johan Dahlin)
  • GtkIconView: Add a default value for the model constructor parameter (Johan Dahlin)
  • Add a default value for column in Gtk.TreeView.get_cell_area() (Johan Dahlin)
  • Atomic inserts in Gtk.{List,Tree}Store overrides (Martin Pitt)
  • Fix Gtk.Button constructor to accept use_stock parameter (Martin Pitt)
  • Correct bad rebase, remove duplicate Window (Johan Dahlin)
  • Add bw-compatible arguments to Gtk.Adjustment (Johan Dahlin)
  • GtkTreePath: make it iterable (Johan Dahlin)
  • Add a default argument to TreeModelFilter.set_visible_func() (Johan Dahlin)
  • Add a default argument to Gtk.TreeView.set_cursor (Johan Dahlin)
  • Add a default argument to Pango.Context.get_metrics() (Johan Dahlin)
  • Fix double-freeing GValues in arrays (Martin Pitt)
  • Renamed “property” class to “Property” (Simon Feltman)
  • Fix Python to C marshalling of GValue arrays (Martin Pitt)
  • Correct the Gtk.Window hierarchy (Johan Dahlin)
  • Renamed getter/setter instance attributes to fget/fset respectively. (Simon Feltman)
  • Add Gtk.Arrow/Gtk.Window constructor override (Johan Dahlin)
  • Fix marshalling to/from Python to work on big endian machines. (Michel Dänzer)
  • Use gi_cclosure_marshal_generic instead of duplicating it. (Michel Dänzer)
  • Override Gtk.TreeView.get_visible_range to fix return (René Stadler)
  • Plug memory leak in _is_union_member (Paolo Borelli)
  • tests: Split TestInterfaces into separate tests (Sebastian Pölsterl)
  • README: Update current maintainers (Martin Pitt)

Read more