summarylogtreecommitdiffstats
path: root/lighttrans.py
diff options
context:
space:
mode:
authorElrondo462018-12-12 08:47:56 +0100
committerElrondo462018-12-12 08:47:56 +0100
commitbdb59d011bde898fe124cec3c9e5406be2460fb7 (patch)
treeafdf14d5053e42eae17eb55037c3ef6f5f870110 /lighttrans.py
parent8d56886c27d0ac3478438d70fd31faca88a9fa56 (diff)
downloadaur-bdb59d011bde898fe124cec3c9e5406be2460fb7.tar.gz
To the BETA1 version
Diffstat (limited to 'lighttrans.py')
-rw-r--r--lighttrans.py164
1 files changed, 87 insertions, 77 deletions
diff --git a/lighttrans.py b/lighttrans.py
index 9ebdc7cac0d..458d9cc2d4b 100644
--- a/lighttrans.py
+++ b/lighttrans.py
@@ -1,134 +1,144 @@
#!/usr/bin/python
-#Created by Baoréla
+# Created, cleaned and commented by Baba Orhum
+# Threaded by Wascar
+# Program in BETA1 (0.50-b1)
+# Importing used modules
import os
+import time
import shutil
import tarfile
import urllib.request
import json
+import glob
+import tempfile
+from threading import Thread
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
+# Can be used in the future versions or... not :)
+# from gi.overrides import GLib
-
+# Thread for the GUI
class Handler:
- def onDestroy(self, *args):
+ def onDestroy(self, *args): # Sure if you quit with the cross the program terminates
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:
+ def onButtonClicked(self, button): # Just starts when you click the button
+ buttonswitcher.set_sensitive(False) # Now the button is greyed, working :)
+ buttonswitcher.set_label('PLEASE WAIT...') # Sure the button text change to this
+ lang = langCombo.get_active_text() # Getting the lang value
+ ver = verCombo.get_active_text() # Getting the version value
+ if lang is None: # If the user don't select the language ERROR BOX
stopTrickingMeLang()
- Gtk.main()
exit(0)
- elif verCombo.get_active_text() is None:
+ elif ver is None: # If the user don't select the version ERROR BOX
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()
+ buttonswitcher.set_sensitive(False) # Preparing and starting the second thread
+ thread = Thread(target=patchThread, args=(tempfile.mkdtemp(), ver, lang))
+ thread.daemon = True
+ thread.start()
builder = Gtk.Builder()
-builder.add_from_file("/opt/lighttrans/transl.glade")
-builder.connect_signals(Handler())
-
-
-def stopTrickingMeLang():
-
+builder.add_from_file("/opt/lighttrans/transl.glade") # Yes the GUI was created with glade and not in pure text :)
+builder.connect_signals(Handler()) # Sure connecting signals to Handler
+
+buttonswitcher = builder.get_object("transButton") # If there is not, the button will be starts nothing
+
+
+def patchThread(tempur, ver, lang): # The second thread
+ sourcetar = 'thunderbird/distribution/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi' # File we want to extract in the tar
+ getlight = 'https://ftp.mozilla.org/pub/thunderbird/releases/' + ver + '/linux-x86_64/' + \
+ LANG[lang] + '/thunderbird-' + ver + '.tar.bz2' #URL for Thunderbird
+ print(getlight)
+ filename = 'thunderbird-' + ver + '.tar.bz2' # Filename in variable
+ urllib.request.urlretrieve(getlight, tempur + '/' + filename) # Getting the file in URL
+ os.rename(tempur + '/thunderbird-' + ver + '.tar.bz2',
+ tempur + '/thunderbird-' + ver + '-' + LANG[lang] + '.tar.bz2') # Optionnal but can be used for debug
+ if not os.path.exists(lang): # For sure :)
+ os.makedirs(tempur + '/' + lang) # Working in temp file
+ tar = tarfile.open(
+ tempur + '/thunderbird-' + ver + '-' + LANG[lang] + '.tar.bz2', 'r') # Opening the tar file
+ ioreader = tar.extractfile(sourcetar) # Extracting
+ with open(tempur + '/' + lang + '/' + extensionname, 'wb') as x:
+ x.write(ioreader.read()) # HERE :)
+ tar.close() # Closing the tar file
+ removeUserLight() # Have to but now without subprocess
+ removeLight() # Get out extension not in my language :)
+ shutil.copyfile(tempur + '/' + lang + '/' + extensionname, primthundpath + '/' + extensionname) # Copy the downloaded extension in correct place
+ shutil.rmtree(tempur + '/' + lang, ignore_errors=True) # Last line before buttonswitcher removing temps
+ os.remove(tempur + '/thunderbird-' + ver + '-' + LANG[lang] + '.tar.bz2')
+ shutil.rmtree(tempur, ignore_errors=True)
+ buttonswitcher.set_label('FINISH CLOSING...') # Better to inform you
+ time.sleep(8) # Better to watch I informed you :)
+ Gtk.main_quit()
+
+def stopTrickingMeLang(): # You have to define language OK :)
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():
+def stopTrickingMeVer(): # You have to define version OK :)
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:
- from subprocess import call
- call('rm /home/*/.thunderbird/*.default/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi', shell=True)
- except OSError:
- pass
+
+def removeLight(): # This removing Lightning extension
try:
- os.remove('/usr/lib/thunderbird/distribution/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ os.remove(secondthundpath + '/' + extensionname)
except OSError:
pass
try:
- os.remove('/usr/lib/thunderbird/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi')
+ os.remove(primthundpath + '/' + extensionname)
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"))
+def removeUserLight(): # This removing Lightning extension in userspace
+ inList = []
+ filelist = glob.glob('/home/*/.thunderbird/*.default')
+ for file in filelist:
+ inList.append(file)
+ for dalek in inList:
+ try:
+ os.remove(dalek + '/extensions/' + extensionname)
+ except:
+ print('FILE NOT FOUND')
+ try:
+ os.remove(dalek + '/addonStartup.json.lz4') # For solving the language collision, have to reactive all extensions at start.
+ except: # Don't like this complain to Mozilla or the creators of Arch or Manjaro
+ print('FILE NOT FOUND')
+
+
+config = json.load(open("/opt/lighttrans/config.json")) # Values for languages and versions, don't like YAML because with its identation system
+extensionname = '{e2fda1a4-762b-4020-b5ad-a41df1933103}.xpi' # Useful in mozilla change extension name
+primthundpath = '/usr/lib/thunderbird/extensions' # Adapt it if necessary for other distros
+secondthundpath = '/usr/lib/thunderbird/distribution/extensions' # Same
+
+# For getting language values (dictionary mode)
LANG = config['langs']
langCombo = builder.get_object("langCombo")
for langloop in LANG.keys():
langCombo.append_text(langloop)
+# For getting language values
THUNDVER = config['versions']
verCombo = builder.get_object("verCombo")
for THUNDERLOOP in THUNDVER:
verCombo.append_text(THUNDERLOOP)
+# Sorry for Main Window name :)
window = builder.get_object("blowWinJob")
window.show_all()
-Gtk.main()
+Gtk.main() \ No newline at end of file