summarylogtreecommitdiffstats
path: root/lighttrans.py
diff options
context:
space:
mode:
authorElrondo462018-12-05 09:08:54 +0100
committerElrondo462018-12-05 09:08:54 +0100
commitc2f1990ece6391518445c7dabac43f4f3b81cd72 (patch)
tree8ca70ae4c473e651c126b63e37aacb8eba60fe00 /lighttrans.py
downloadaur-c2f1990ece6391518445c7dabac43f4f3b81cd72.tar.gz
First Public Alpha
Diffstat (limited to 'lighttrans.py')
-rw-r--r--lighttrans.py129
1 files changed, 129 insertions, 0 deletions
diff --git a/lighttrans.py b/lighttrans.py
new file mode 100644
index 00000000000..dec28cac82a
--- /dev/null
+++ b/lighttrans.py
@@ -0,0 +1,129 @@
+#!/usr/bin/python
+#Created by Baoréla
+
+import os
+import shutil
+import tarfile
+import urllib.request
+import json
+
+import gi
+
+gi.require_version('Gtk', '3.0')
+from gi.repository import Gtk
+
+
+class Handler:
+ def onDestroy(self, *args):
+ Gtk.main_quit()
+
+ def onClickRemLight(self, button):
+ removeLight()
+ SuccessLight()
+ Gtk.main()
+
+ def onButtonClicked(self, button):
+ shutil.rmtree('/tmp/lighttrans/', ignore_errors=True)
+ lang = langCombo.get_active_text()
+ if lang is None:
+ stopTrickingMeLang()
+ Gtk.main()
+ exit(0)
+ elif verCombo.get_active_text() is None:
+ stopTrickingMeVer()
+ Gtk.main()
+ exit(0)
+ else:
+ os.makedirs('/tmp/lighttrans/')
+ getlight = 'https://ftp.mozilla.org/pub/thunderbird/releases/' + verCombo.get_active_text() + '/linux-x86_64/' + \
+ LANG[lang] + '/thunderbird-' + verCombo.get_active_text() + '.tar.bz2'
+ print(getlight)
+ filename = 'thunderbird-' + verCombo.get_active_text() + '.tar.bz2'
+ urllib.request.urlretrieve(getlight, '/tmp/lighttrans/' + filename)
+ os.rename('/tmp/lighttrans/thunderbird-' + verCombo.get_active_text() + '.tar.bz2',
+ '/tmp/lighttrans/thunderbird-' + verCombo.get_active_text() + '-' + LANG[lang] + '.tar.bz2')
+ if not os.path.exists(lang):
+ os.makedirs('/tmp/lighttrans/' + lang)
+ tar = tarfile.open(
+ '/tmp/lighttrans/thunderbird-' + verCombo.get_active_text() + '-' + LANG[lang] + '.tar.bz2', 'r')
+ ioreader = tar.extractfile(
+ 'thunderbird/distribution/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ with open('/tmp/lighttrans/' + lang + '/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi', 'wb') as x:
+ x.write(ioreader.read())
+ tar.close()
+ try:
+ os.remove('/usr/lib/thunderbird/distribution/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ except OSError:
+ pass
+ try:
+ os.remove('/usr/lib/thunderbird/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ except OSError:
+ pass
+ shutil.copyfile('/tmp/lighttrans/' + lang + '/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi',
+ '/usr/lib/thunderbird/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ shutil.rmtree('/tmp/lighttrans/' + lang, ignore_errors=True)
+ os.remove('/tmp/lighttrans/thunderbird-' + verCombo.get_active_text() + '-' + LANG[lang] + '.tar.bz2')
+ shutil.rmtree('/tmp/lighttrans/', ignore_errors=True)
+ Success()
+
+
+builder = Gtk.Builder()
+builder.add_from_file("/opt/lighttrans/transl.glade")
+builder.connect_signals(Handler())
+
+
+def stopTrickingMeLang():
+
+ dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "FATAL")
+ dialog.format_secondary_text("You have to choose a target language")
+ dialog.run()
+ dialog.destroy()
+
+def stopTrickingMeVer():
+
+ dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.OK, "FATAL")
+ dialog.format_secondary_text("You have to choose thunderbird version")
+ dialog.run()
+ dialog.destroy()
+
+def removeLight():
+ try:
+ os.remove('/usr/lib/thunderbird/distribution/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ except OSError:
+ pass
+ try:
+ os.remove('/usr/lib/thunderbird/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ except OSError:
+ pass
+
+def Success():
+ dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Complete")
+ dialog.set_position(Gtk.WindowPosition.CENTER)
+ dialog.format_secondary_text("Translate successfull, will now close")
+ dialog.run()
+ dialog.destroy()
+ exit(0)
+
+def SuccessLight():
+ dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Complete")
+ dialog.set_position(Gtk.WindowPosition.CENTER)
+ dialog.format_secondary_text("Lightning is now removed, please start and quit thunderbird before translate process")
+ dialog.run()
+ dialog.destroy()
+
+config = json.load(open("/opt/lighttrans/config.json"))
+LANG = config['langs']
+langCombo = builder.get_object("langCombo")
+for langloop in LANG.keys():
+ langCombo.append_text(langloop)
+
+THUNDVER = config['versions']
+
+verCombo = builder.get_object("verCombo")
+for THUNDERLOOP in THUNDVER:
+ verCombo.append_text(THUNDERLOOP)
+
+window = builder.get_object("blowWinJob")
+window.show_all()
+
+Gtk.main()