2 # A graphical way to "git pull" from the repository
3 # 2009-04-27 Thomas Perl <thpinfo.com>
13 git_checkout_root
= os
.path
.abspath(os
.path
.join(os
.path
.dirname(sys
.argv
[0]), '..', '..'))
15 class GitPullWindow(gtk
.Window
):
17 gtk
.Window
.__init
__(self
)
18 self
.set_title('Git updater for gPodder')
19 self
.set_position(gtk
.WIN_POS_CENTER_ALWAYS
)
20 self
.connect('destroy', gtk
.main_quit
)
22 self
.text_buffer
= gtk
.TextBuffer()
23 self
.text_view
= gtk
.TextView(self
.text_buffer
)
24 self
.text_view
.set_editable(False)
26 self
.sw
= gtk
.ScrolledWindow()
27 self
.sw
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_AUTOMATIC
)
28 self
.sw
.add(self
.text_view
)
30 self
.vadj
= self
.sw
.get_vadjustment()
35 self
.thread
= threading
.Thread(target
=self
.thread_code
)
38 def add_text(self
, text
):
39 self
.text_buffer
.insert(self
.text_buffer
.get_end_iter(), text
)
41 def thread_code(self
):
42 global git_checkout_root
43 command_line
= ['git', 'pull', '-v']
44 gobject
.idle_add(self
.add_text
, 'Using checkout root: %s\n' % git_checkout_root
)
45 gobject
.idle_add(self
.add_text
, 'Calling: %s\n' % (' '.join(command_line
)))
46 process
= subprocess
.Popen(command_line
,
47 stdout
=subprocess
.PIPE
,
48 stderr
=subprocess
.STDOUT
,
49 cwd
=git_checkout_root
)
50 for line
in process
.stdout
:
51 gobject
.idle_add(self
.add_text
, line
)
53 result
= process
.wait()
55 gobject
.idle_add(self
.add_text
, '\n\nFinished successfully. You can close this window now.')
57 gobject
.idle_add(self
.add_text
, '\n\nThere was an error while executing Git. Status: %d' % result
)
60 if __name__
== '__main__':
61 gobject
.threads_init()