This file is indexed.

/usr/bin/mediawiki2latex-pyqt is in mediawiki2latexguipyqt 1.3-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#! /usr/bin/python3
# -*- coding: utf-8 -*-
# 	$Id$

License="""\
mediawiki2latex-pyqt version {version}:

a gui for mediawiki2latex

{authors}

This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see
<http://www.gnu.org/licenses/>.
"""

version="1.2"

authors="""Copyright © 2014 Dirk Hünniger <dirk.hunniger@googlemail.com>
Copyright © 2014 Georges Khaznadar <georgesk@debian.org>"""

import sys
from PyQt4.QtGui import QLabel, QApplication, qApp, QMainWindow, QLineEdit
from PyQt4.QtGui import QProgressBar, QPushButton, QGridLayout, QComboBox
from PyQt4.QtGui import QMessageBox, QIcon, QDialog
from PyQt4.QtCore import SIGNAL, QTimer, pyqtSignal, QProcess, Qt
from PyQt4.QtCore import QTranslator, QLibraryInfo, qDebug
import webbrowser
import os
import tempfile
import time
import math
# access custom modules
sys.path = sys.path + ['/usr/share/mediawiki2latex']
from Ui_MainWindow import Ui_MainWindow
#from Ui_about import Ui_Dialog as Ui_about
from processes import bashProcess
from processTimer import processTimer

# i18n and l10n stuff
from locale import getdefaultlocale
locale = getdefaultlocale()

try:
  from PyQt4 import QtCore
  _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
  def _fromUtf8(s):
    return s

  try:
    _encoding = QApplication.UnicodeUTF8
    def _translate(context, text, disambig=None):
      return QApplication.translate(context, text, disambig, _encoding)
  except AttributeError:
    def _translate(context, text, disambig=None):
      return QApplication.translate(context, text, disambig)

class Progressor:
  def __init__(self):
    self.expectedRuntime=60.0
    self.lastReachedKnownRelativeProgress=0.0
    self.timeOfLastReachedKnownRelativeProgress=time.time()
    self.expectedRealiveProgresses=[
      (_translate("MainWindow",'downloading article and contributor information'), 
       0.02540431143798292),
      (_translate("MainWindow",'parsing article text'), 
       0.057625916241286344),
      (_translate("MainWindow",'forking threads to download of images and contributor information on them'),
       0.058045207449988465),
      (_translate("MainWindow",'precompiling table columns'), 
       0.08075814224942594),
      (_translate("MainWindow",'joining threads to download the images and contributor information on them'),
       0.37003149457779727),
      (_translate("MainWindow",'preparing for PDF generation'),
       0.5479855803098518),
      (_translate("MainWindow",'preparing images for LaTeX document'),
       0.637605216120732),
      (_translate("MainWindow",'generating PDF file. LaTeX run 1 of 4'), 
       0.6911489294291799),
      (_translate("MainWindow",'generating PDF file. LaTeX run 2 of 4'), 
       0.7673758195622185),
      (_translate("MainWindow",'generating PDF file. LaTeX run 3 of 4'), 
       0.8463397892914045),
      (_translate("MainWindow",'generating PDF file. LaTeX run 4 of 4'),
       0.9231746180088297),
      (_translate("MainWindow",'finished'), 
         1.0)
       ]
    self.startTime=time.time()
    self.progressBarValue=0.0
    self.estimatedRelativeProgress=0.0
    self.lastRuntime=0.0
    self.nextKnownRelativeProgressToBeReached=self.expectedRealiveProgresses[0][1]
  def __call__(self,line):
    for (k,v) in self.expectedRealiveProgresses:
      if k in line:
        if k=='finished': 
          self.progressBarValue=1.0
          return 100
        self.lastReachedKnownRelativeProgress=v
        for i,(kk,vv) in enumerate(self.expectedRealiveProgresses):
          if kk==k: n=i
        n=min(max(0,n+1),len(self.expectedRealiveProgresses)-1)
        self.nextKnownRelativeProgressToBeReached=self.expectedRealiveProgresses[n][1]
        self.timeOfLastReachedKnownRelativeProgress=time.time()
        self.expectedRuntime=(time.time()-self.startTime)/self.lastReachedKnownRelativeProgress
    self.runtime=time.time()-self.startTime
    self.p=self.lastReachedKnownRelativeProgress+(1-math.exp(-(time.time()-self.timeOfLastReachedKnownRelativeProgress)/(self.expectedRuntime*(self.nextKnownRelativeProgressToBeReached-self.lastReachedKnownRelativeProgress))))*(self.nextKnownRelativeProgressToBeReached-self.lastReachedKnownRelativeProgress)
    self.progressBarValue=self.progressBarValue+(max((self.p-self.progressBarValue)*(self.runtime-self.lastRuntime)/5.0,0.0))
    self.progressBarValue=self.p
    self.lastRuntime=self.runtime
    return int(self.progressBarValue*100.0)

class sequenceApp (QApplication):
    """
    implements a particular qt4 Application which allows to
    manage sequencial procedure lists coupled with a monitor : 
    informations about the pending procedure, progress bar, and
    text browsers for the stdout and stderr streams.
    """
    def outBrowser(self):
        """
        abstract function to overload. Should return a widget where
        stdout can be fed in.
        """
        return None

    def errBrowser(self):
        """
        abstract function to overload. Should return a widget where
        stderr can be fed in.
        """
        return None

    def registerProgress(self,n):
        """
        abstract function to overload. Should update a progress bar.
        @param n a numeric value between 0 and 100
        """
        self.pbar.setValue(n)
        return None

    def nextProcess(self, finished="echo 'abstract command line'"):
        """
        abstract function to overload. Registers that a process is finished
        @param finished the text of a shell command line which was processed
        """
        return None


class MainWindow (QMainWindow,sequenceApp):
    """
    the main window of the GUI.
    """

    """
    specific signal which will be triggered by the processTimer object
    """
    idleTick          = pyqtSignal()
    idleDetailProgress = pyqtSignal(int)

    def outBrowser(self):
        """
        @return a QPlainTextEdit instance to be fed with stdout
        """
        return self.ui.plainTextEdit
    
    def errBrowser(self):
        """
        @return a QPlainTextEdit instance to be fed with stderr
        """
        return self.ui.plainTextEdit_2
    
    def registerProgress(self,n):
        """
        Update the progress bar.
        @param n a numeric value between 0 and 100
        """
        n=float(n) # might be something more complex
        if n > 100:
            n=100
        if n < 0:
            n=0
        self.pbar.setValue(n)
        return

    def nextProcess(self, finished=None):
        """
        increments the pointer to the list of processes to deal with
        @param finished the text of a shell command line which was processed
        """
        if finished==None:
          finished=_translate("MainWindow","echo 'default message; you should not see it'")
        self.pending = self.pending +1
        message = "`{0}' done.".format(finished)
        self.ui.statusbar.showMessage(message,1000)
        return

    def __init__ (self, preferences):
        """
        constructor of the main window
        @param preferences an instance of Preferences
        """
        QMainWindow.__init__ (self)
        sequenceApp.__init__ (self)
        self.processList=[]        # list of bashProcess instances
        self.pending=0             # pointer to self.processList
        self.t=processTimer(self)  # this timer will triggers idleTick.emit()
        self.idleTick.connect(self.tick)
        self.idleDetailProgress.connect(self.registerProgress)
        outFile=tempfile.NamedTemporaryFile(suffix='.pdf',prefix='m2l_',delete=False)
        self.outFilename=outFile.name
        outFile.close()

        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        self.edit = self.ui.lineEdit
        self.edit.setText(preferences.mwSource)

        self.combo = self.ui.comboBox
        self.papercombo = self.ui.comboBox_2
        self.rastercombo = self.ui.comboBox_3
        self.inccombo = self.ui.comboBox_4
        self.button = self.ui.runButton
        self.ui.runButton.clicked.connect(self.callbackrun)
        self.ui.actionQuit.triggered.connect(self.close)
        self.ui.actionSave_preferences.triggered.connect(self.savePrefs)
        self.ui.actionHelp.triggered.connect(self.help)
        self.ui.actionAbout_F1.triggered.connect(self.about)
        self.pbar = self.ui.progressBar
        self.pbar.setValue(0)
        self.ui_about()
        self.resize(700,400)
        self.ui.plainTextEdit.setReadOnly(True)

    def ui_about(self):
      """
      create the about dialog
      """
      self.about=QDialog(self, Qt.CustomizeWindowHint|Qt.WindowTitleHint) # no close button in the window's top
      self.about.ui=QDialog(self)#Ui_about()
      #self.about.ui.setupUi(self.about)
      #self.about.ui.textAuthors.setText(authors)
      theLicense=_translate("MainWindow","""\
mediawiki2latex-pyqt version {version}:

a gui for mediawiki2latex

{authors}

This program is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 2 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see
<http://www.gnu.org/licenses/>.
""")
      #self.about.ui.textLicense.setText(theLicense.format(version=version, authors=""))
      #self.about.ui.textTranslations.setText(_translate("MainWindow","""French translation: (c) 2014 Georges Khaznadar <georgesk@debian.org>
#"""))
      self.about.hide()
      return

    def about(self):
      """
      raise the "about" dialog
      """
      #self.about.show()
      #result = self.about.exec_()
      #self.about.hide()
      qDebug("about not yet implemented")
      return

    def help(self):
      """
      raise a help window
      """
      qDebug("help not yet implemented")
      return

    def savePrefs(self):
      """
      callback function to save preferences
      """
      qDebug("savePrefs not yet implemented")
      return

    def pdfFile(self):
        """
        returns the path to the output file
        @return the path to the PDF file
        """
        if self.getZip(self.inccombo.currentText())=="-z":
          return ".".join(self.outFilename.split(".")[:-1])+".zip"             
        return self.outFilename
 
    def callbackrun(self):
        """
        Callback function that is called when the user clicks the run button.
        """
        try:
            if os.path.exists(self.pdfFile()):
                mainfile = open(self.pdfFile(), "ab")
                mainfile.close()
        except:
            QMessageBox.about(self, _translate("MainWindow","File still open"), 
              _translate("MainWindow","""Please close your PDF viewer before pressing the run button!
This program need writing permission on the PDF file!"""))
            return

        self.pending = 0
        self.processList=[]
        self.button.setEnabled(False)
        logBrowserTab=1 # displays stdout
        self.outBrowser().appendPlainText(_translate("MainWindow","Mediawiki to Latex started..."))
        self.ui.tabWidget.setCurrentIndex(logBrowserTab)
        self.scheduleM2L()
        # more processes can be scheduled, the module processes.py allows it.
        self.t.start()

    def tick(self):
        """
        callback procedure triggered by processTimer's ticks
        """
        if self.pending < len(self.processList):
            pp = self.processList[self.pending]
            if pp and pp.state()==QProcess.NotRunning:
                pp.start()
                self.ui.statusbar.showMessage(pp.message)
                #self.setDetailProgress(0)
                #self.setProgress()
        else:
            # no more processes to run
            self.bailOut()

    def getSwitch(self, switch):
        if switch==_translate("MainWindow","MediaWiki"): return " -m "
        if switch==_translate("MainWindow","Normal"): return " -i "
        return ""
    def getVector(self, switch):
        if switch==_translate("MainWindow","Rasterize"): return ""
        return "-g"
    def getZip(self, switch):
        if switch==_translate("MainWindow","LaTeX Source Zip"): return "-z"
        return ""

    def scheduleM2L(self):
        """
        Schedules mediawiki2latex with the right arguments, redirecting
        stdout and stderr to browsers.
        """
        cmd = "mediawiki2latex -u {0} {1} {2} {3} -o {4}".format(
            self.edit.text(),
            self.getSwitch(self.combo.currentText()),
            self.getVector(self.rastercombo.currentText()),
            self.getZip(self.inccombo.currentText()),
            self.pdfFile(),
            )
        # the parameter expect=10000 means that 10000 lines are expected in
        # stdout. This parameter can be also a pattern compiled as a regular
        # expression or a callable to filter lines of stdout.
        bp=bashProcess(self, cmd=cmd, message=_translate("MainWindow","running mediawiki2latex"),
                       expect=Progressor())
        self.processList.append(bp)
        return

    def closeEvent(self, event):
        """
        callback function called when this window is closed.
        may raise a warning dialog if a process is still running.
        """
        # try to erase the temporary PDF file
        if os.path.exists(self.pdfFile()):
            try:
                os.unlink(self.pdfFile());
            except:
                pass
        QMainWindow.closeEvent(self,event);

    def bailOut(self):
        """
        Notifies the end of the sequence of processes. Launches a
        viewer for the output PDF file.
        """
        self.ui.statusbar.showMessage(_translate("MainWindow","The sequence of processes is finished. You can close the window."))
        self.t.stop() # end of tick service
        self.button.setEnabled(True)
        self.pbar.setValue(100)
        self.ui.tabWidget.setCurrentIndex(0)
        webbrowser.open('file://{0}'.format(os.path.abspath(self.pdfFile())))
        return

class Preferences(object):
    """
    User preferences for Mediawiki2latex
    """
    def __init__(self,
                 mwSource="http://en.wikipedia.org/wiki/Homomorphism",
                 ):
        """
        the constructor
        @param mwSource the URL to use as a source, defaults to "http://en.wikipedia.org/wiki/Homomorphism"
        """
        self.mwSource=mwSource
        return

def translationStuff():
  """
  Installs translators
  """
  translationPaths=[QLibraryInfo.location(QLibraryInfo.TranslationsPath),
                    '/usr/share/mediawiki2latex/translations',
                    'lang/translations']
  for transFile in ("qt_{locale}", "mediawiki2latex-gui-{locale}"):
    transFile=transFile.format(locale=locale[0])
    translator = QTranslator()
    for path in translationPaths:
      if translator.load(transFile, path):
        qApp.installTranslator(translator)
        break
  return

#--------------- main ------------------
if __name__ == '__main__':
  APP = QApplication(sys.argv)
  #translationStuff()
  translationPaths=[QLibraryInfo.location(QLibraryInfo.TranslationsPath),
                    '/usr/share/mediawiki2latex/translations',
                    'lang/translations']
  for transFile in ("qt_{locale}", "mediawiki2latex-gui-{locale}"):
    transFile=transFile.format(locale=locale[0])
    translator = QTranslator()
    for path in translationPaths:
      if translator.load(transFile, path):
        APP.installTranslator(translator)
        break

  # style = QStyleFactory.create('Cleanlooks')
  # APP.setStyle(style)
      
  preferences = Preferences() # should read some user config file
  MAINWINDOW = MainWindow (preferences)
  MAINWINDOW.setWindowIcon(QIcon('logo.ico'))
  MAINWINDOW.show ()
  APP.exec_ ()

### for Emacs ###
# Local Variables:
# mode: python
# End: