summarylogtreecommitdiffstats
path: root/lighttrans.py
diff options
context:
space:
mode:
authorElrondo462018-12-14 22:30:09 +0100
committerElrondo462018-12-14 22:30:09 +0100
commit575c0f365abc958345af482820b56bafc3dfe500 (patch)
tree21e0f34f57bdbd22da7151265af1fbcc44d695b3 /lighttrans.py
parentbdb59d011bde898fe124cec3c9e5406be2460fb7 (diff)
downloadaur-575c0f365abc958345af482820b56bafc3dfe500.tar.gz
fixed crash thread bug
Diffstat (limited to 'lighttrans.py')
-rw-r--r--lighttrans.py138
1 files changed, 67 insertions, 71 deletions
diff --git a/lighttrans.py b/lighttrans.py
index 458d9cc2d4b..02ddad18fac 100644
--- a/lighttrans.py
+++ b/lighttrans.py
@@ -5,7 +5,6 @@
# Importing used modules
import os
-import time
import shutil
import tarfile
import urllib.request
@@ -18,10 +17,17 @@ import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
+from gi.overrides import GLib
# Can be used in the future versions or... not :)
# from gi.overrides import GLib
# Thread for the GUI
+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
+
+
class Handler:
def onDestroy(self, *args): # Sure if you quit with the cross the program terminates
Gtk.main_quit()
@@ -32,11 +38,11 @@ class Handler:
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()
- exit(0)
+ stopTrickingMe("You have to choose a target language")
+ return False
elif ver is None: # If the user don't select the version ERROR BOX
- stopTrickingMeVer()
- exit(0)
+ stopTrickingMe("You have to choose thunderbird version")
+ return False
else:
buttonswitcher.set_sensitive(False) # Preparing and starting the second thread
thread = Thread(target=patchThread, args=(tempfile.mkdtemp(), ver, lang))
@@ -44,50 +50,42 @@ class Handler:
thread.start()
-builder = Gtk.Builder()
-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(): # 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")
+ try:
+ 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)
+ GLib.idle_add(doneSoft) # Better to inform you
+ except OSError:
+ GLib.idle_add(stopTrickingMe("GENERAL EXCEPTION"))
+
+def doneSoft():
+ buttonswitcher.set_label('DONE PLEASE CLOSE')
+
+
+def stopTrickingMe(text): # You have to define version OK :)
+ dialog = Gtk.MessageDialog(parent=Gtk.Window(), flags=0, message_type=Gtk.MessageType.ERROR,
+ buttons=Gtk.ButtonsType.OK, text="FATAL")
+ dialog.format_secondary_text(text)
dialog.run()
dialog.destroy()
@@ -104,41 +102,39 @@ def removeLight(): # This removing Lightning ex
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)
+ os.remove(file + '/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.
+ os.remove(file + '/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
+if __name__ == '__main__':
+ builder = Gtk.Builder()
+ 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
-# 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 (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']
+ # For getting language values
+ THUNDVER = config['versions']
-verCombo = builder.get_object("verCombo")
-for THUNDERLOOP in THUNDVER:
- verCombo.append_text(THUNDERLOOP)
+ 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()
+ # Sorry for Main Window name :)
+ window = builder.get_object("blowWinJob")
+ window.show_all()
-Gtk.main() \ No newline at end of file
+ Gtk.main()