Delete files on MP3 player before syncing files (bug 573)
[gpodder.git] / doc / dev / update-git-gui.py
blob98e984c36cbb5d2d675d4c0c011cba97ab1524fd
1 #!/usr/bin/python
2 # A graphical way to "git pull" from the repository
3 # 2009-04-27 Thomas Perl <thpinfo.com>
5 import gtk
6 import gobject
7 import subprocess
8 import time
9 import threading
10 import sys
11 import os
13 git_checkout_root = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..', '..'))
15 class GitPullWindow(gtk.Window):
16 def __init__(self):
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)
29 self.add(self.sw)
30 self.vadj = self.sw.get_vadjustment()
32 self.resize(700, 400)
33 self.show_all()
35 self.thread = threading.Thread(target=self.thread_code)
36 self.thread.start()
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()
54 if result == 0:
55 gobject.idle_add(self.add_text, '\n\nFinished successfully. You can close this window now.')
56 else:
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()
62 GitPullWindow()
63 gtk.main()