Difference between revisions of "Avdump GUI"

Jump to navigation Jump to search
24,290 bytes removed ,  13:38, 6 June 2011
no edit summary
Line 49: Line 49:
</pre>
</pre>


==Source==
==Sourcecode==
This GUI was coded purely in python using pyqt for the framework.
This GUI was coded purely in python using pyqt for the framework.
 
The sourcecode can be found in the [http://dev.anidb.net/websvn/listing.php?repname=AniDB+CSS&path=%2Ftrunk%2Fudp_clients%2Favdump-gui%2F#_trunk_udp_clients_avdump-gui_ svn].
===avdump2gui.pyw===
<pre  style="font-size: 60%;">
import sys, os, platform, subprocessw, ConfigParser, string, unicodedata
 
from time import time
 
# Import Qt modules
from PyQt4 import QtCore, QtGui
 
# Import the compiled UI module
from gui import Ui_MainWindow
 
# Create a class for our main window
class Main(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self._ui = Ui_MainWindow()
        self._ui.setupUi(self)
        self._filelist = {}
        self._paths = {}
        self._done_files = []
        self._worker = None
        self._export_filename = 'exports/export_' + str(int(time())) + '.txt'
        self._allowed_extensions = ('avi', 'mpg', 'mpeg', 'ts', 'm2ts', 'rm', 'rmvb', 'asf', 'wmv', 'mov', 'qt', 'ogm',
                                  'mp4', 'mkv', 'swf', 'flv', 'ogv', 'webm', 'mk3d', 'srt', 'sub', 'ssa', 'smi', 'idx', 'ass',
                                  'txt', 'mks', 'lrc', 'rt', 'tmp', 'js', 'pjs', 'tts', 'xss', 'mp3', 'aac', 'ac3', 'dts', 'wav',
                                  'flac', 'wma', 'mka', 'ra', 'ogg', 'm4a', 'dtshd', 'thd', 'rar', 'zip', 'ace', '7z', 'smil')
 
        tmp = []
        for ext in self._allowed_extensions:
            tmp.append('*.' + ext)
 
        self._allowed_extensions_str = "; ".join(tmp)
 
        self._ui.datatable.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self._ui.datatable.setColumnWidth(0, 90)
        self._ui.datatable.setColumnWidth(1, 250)
        self._ui.datatable.setColumnWidth(2, 40)
 
        self.connect(self._ui.files_button, QtCore.SIGNAL("clicked()"), self._slotFile)
        self.connect(self._ui.folder_button, QtCore.SIGNAL("clicked()"), self._slotFolder)
        self.connect(self._ui.start_button, QtCore.SIGNAL("clicked()"), self._run)
        self.connect(self._ui.stop_button, QtCore.SIGNAL("clicked()"), self._stop)
        self.connect(QtGui.QAction(self), QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
 
        self._enable_elements()
        self._read_config()
        self._read_done()
 
#################################################
#                                              #
#                GUI FUNCTIONS                #
#                                              #
#################################################
 
    def _disable_elements(self):
        self._ui.username.setDisabled(True)
        self._ui.apikey.setDisabled(True)
        self._ui.files_button.setDisabled(True)
        self._ui.folder_button.setDisabled(True)
        self._ui.done.setDisabled(True)
        self._ui.exp.setDisabled(True)
        self._ui.start_button.setDisabled(True)
        self._ui.stop_button.setEnabled(True)
 
    def _enable_elements(self):
        self._ui.username.setEnabled(True)
        self._ui.apikey.setEnabled(True)
        self._ui.files_button.setEnabled(True)
        self._ui.folder_button.setEnabled(True)
        self._ui.done.setEnabled(True)
        self._ui.exp.setEnabled(True)
        self._ui.start_button.setEnabled(True)
        self._ui.stop_button.setDisabled(True)
 
    def _output_export(self):
        self._ui.ed2k_export.setText("".join(file(self._export_filename).readlines()))
 
    def _calculate_progress(self):
        if self._ui.datatable.rowCount() == 0:
            return 0
 
        done = 0
        for i in range(self._ui.datatable.rowCount()):
            if unicode(self._ui.datatable.item(i,2).text()) == 'done':
                done += 1
 
        return done*100/self._ui.datatable.rowCount()
 
#################################################
#                                              #
#                EVENT HANDLER                #
#                                              #
#################################################
    def _closeEvent(self,event):
        self._stop()
        self._write_config()
        event.accept()
 
    def _done(self, path):
        i = self._paths[path]
        item = QtGui.QTableWidgetItem('done')
        self._ui.datatable.setItem(i, 2, item)
        if self._ui.exp.isChecked():
            self._output_export()
        self._ui.progressBar.setValue(self._calculate_progress())
 
    def _finished(self):
        self._paths = {}
        self._ui.progressBar.setValue(self._calculate_progress())
        self._worker = None
        self._enable_elements()
        if self._ui.exp.isChecked():
            self._output_export()
 
    def _stop(self):
        if self._worker is not None:
            self._worker.stop()
            self._output_export()
            self._enable_elements()
 
    def _slotFile(self):
        files = QtGui.QFileDialog.getOpenFileNames(self, 'File select', os.getcwd(), self._allowed_extensions_str)
        for path in files:
            self._add_file(unicode(path))
 
    def _slotFolder(self):
        path = unicode(QtGui.QFileDialog.getExistingDirectory(self, "Select Directory"))
        if path != '':
            for root, dir, files in os.walk(path):
                for filename in files:
                    self._add_file(os.path.join(root, filename))
 
    def _add_file(self, fileloc):
        if len(fileloc) == 0:
            return
        elif unicodedata.normalize('NFKC', fileloc) in self._done_files:
            return
 
        no = self._ui.datatable.rowCount()
 
        if platform.system().lower() == 'windows':
            fileloc = fileloc.replace("/", "\\")
            filepath, filename = fileloc.rsplit("\\", 1)
        else:
            filepath, filename = fileloc.rsplit("/", 1)
 
        tmp, ext = filename.rsplit('.', 1)
        if ext not in self._allowed_extensions:
            return
 
        if fileloc not in self._filelist.keys():
            self._filelist[fileloc] =  1
            self._ui.datatable.insertRow(no)
 
            item = QtGui.QTableWidgetItem(filepath)
            self._ui.datatable.setItem(no, 0, item)
 
            item = QtGui.QTableWidgetItem(filename)
            self._ui.datatable.setItem(no, 1, item)
 
            item = QtGui.QTableWidgetItem('new')
            self._ui.datatable.setItem(no, 2, item)
            self._ui.progressBar.setValue(self._calculate_progress())
 
    def _run(self):
        username = unicode(self._ui.username.text())
        apikey  = unicode(self._ui.apikey.text())
 
        if self._ui.datatable.rowCount() == 0:
            QtGui.QMessageBox.information(self, "Error!", "No files to scan in list.", QtGui.QMessageBox.Ok)
            return
        elif not os.path.exists('avdump2cl.exe'):
            QtGui.QMessageBox.information(self, "Error!", "Avdump2cl.exe not found.", QtGui.QMessageBox.Ok)
            return
        elif len(username) == 0 or len(apikey) == 0:
            QtGui.QMessageBox.information(self, "Error!", "No username and/or api-key specified!", QtGui.QMessageBox.Ok)
            return
 
        paths    = []
        for i in range(self._ui.datatable.rowCount()):
            if unicode(self._ui.datatable.item(i,2).text()) == 'new':
                path = os.path.join(unicode(self._ui.datatable.item(i,0).text()), unicode(self._ui.datatable.item(i,1).text()))
                paths.append(path)
                self._paths[path] = i
 
        if len(paths) > 0:
            self._ui.progressBar.setValue(self._calculate_progress())
            self._disable_elements()
            done    = ''
            if self._ui.done.isChecked() is True:
                done = '-done:done.txt'
 
            exp      = ''
            if self._ui.exp.isChecked() is True:
                if not os.path.exists('exports'):
                    os.mkdir('exports')
                exp  = '-exp:' + self._export_filename
               
            self._worker = avdump_worker(username, apikey, done, exp, paths)
            self.connect(self._worker, QtCore.SIGNAL("done"), self._done)
            self.connect(self._worker, QtCore.SIGNAL("finished"), self._finished)
            self._worker.start()         
 
#################################################
#                                              #
#              CONFIG READ/WRITE              #
#                                              #
#################################################
    def _read_config(self):
        if os.path.exists('options.ini'):
            config = ConfigParser.ConfigParser()
            config.read('options.ini')
            self._ui.username.setText(config.get('DEFAULT', 'username'))
            self._ui.apikey.setText(config.get('DEFAULT', 'apikey'))
            if config.get('DEFAULT', 'done') == '1':
                self._ui.done.setChecked(True)
            else:
                self._ui.done.setChecked(False)
 
            if config.get('DEFAULT', 'exp') == '1':
                self._ui.exp.setChecked(True)
            else:
                self._ui.exp.setChecked(False)
 
    def _write_config(self):
        config = ConfigParser.ConfigParser()
        config.set("DEFAULT", "username", str(self._ui.username.text()))
        config.set("DEFAULT", "apikey", str(self._ui.apikey.text()))
        if self._ui.done.isChecked():
            config.set("DEFAULT", "done", 1)
        else:
            config.set("DEFAULT", "done", 0)
        if self._ui.exp.isChecked():
            config.set("DEFAULT", "exp", 1)
        else:
            config.set("DEFAULT", "exp", 0)
        config.write(file("options.ini", "w"))
 
    def _read_done(self):
        if os.path.exists("done.txt"):
            for line in file("done.txt"):
                self._done_files.append(unicodedata.normalize('NFKC', line.decode("utf8").strip()))
 
class avdump_worker(QtCore.QThread):
    def __init__(self, username, apikey, done, exp, paths):
        QtCore.QThread.__init__(self, parent=None)
        self._username    = username
        self._apikey      = apikey
        self._done        = done
        self._exp        = exp
        self._paths      = paths
        self._was_stopped = False
        self._avdump      = None
 
    def stop(self):
        self._was_stopped = True
        self._avdump.terminate()
 
    def run(self):
        for path in self._paths:
            if self._was_stopped is True:
                break
            self._avdump = subprocessw.Popen((u'avdump2cl.exe -ac:%s:%s %s %s "%s"') %(self._username, self._apikey, self._done, self._exp, path))
            self._avdump.communicate()
            if self._was_stopped is False:
                self.emit(QtCore.SIGNAL('done'), path)
 
        if self._was_stopped is False:
            self.emit(QtCore.SIGNAL('finished'))
 
def main():
    app = QtGui.QApplication(sys.argv)
    window=Main()
    window.show()
    sys.exit(app.exec_())
 
if __name__ == "__main__":
    main()
</pre>
 
===gui.py===
<pre  style="font-size: 60%;">
# -*- coding: utf-8 -*-
 
# Form implementation generated from reading ui file 'C:\Python27\Lib\site-packages\PyQt4\avdump.ui'
#
# Created: Fri Jun 03 11:19:16 2011
#      by: PyQt4 UI code generator 4.8.1
#
# WARNING! All changes made in this file will be lost!
 
from PyQt4 import QtCore, QtGui
 
try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s
 
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(600, 400)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        MainWindow.setMinimumSize(QtCore.QSize(600, 400))
        MainWindow.setMaximumSize(QtCore.QSize(600, 400))
        self.main = QtGui.QWidget(MainWindow)
        self.main.setObjectName(_fromUtf8("main"))
        self.username_box = QtGui.QGroupBox(self.main)
        self.username_box.setGeometry(QtCore.QRect(430, 10, 165, 51))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.username_box.sizePolicy().hasHeightForWidth())
        self.username_box.setSizePolicy(sizePolicy)
        self.username_box.setObjectName(_fromUtf8("username_box"))
        self.username = QtGui.QLineEdit(self.username_box)
        self.username.setGeometry(QtCore.QRect(10, 20, 145, 20))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.username.sizePolicy().hasHeightForWidth())
        self.username.setSizePolicy(sizePolicy)
        self.username.setObjectName(_fromUtf8("username"))
        self.api_box = QtGui.QGroupBox(self.main)
        self.api_box.setGeometry(QtCore.QRect(430, 60, 165, 51))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.api_box.sizePolicy().hasHeightForWidth())
        self.api_box.setSizePolicy(sizePolicy)
        self.api_box.setObjectName(_fromUtf8("api_box"))
        self.apikey = QtGui.QLineEdit(self.api_box)
        self.apikey.setGeometry(QtCore.QRect(10, 20, 145, 20))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.apikey.sizePolicy().hasHeightForWidth())
        self.apikey.setSizePolicy(sizePolicy)
        self.apikey.setObjectName(_fromUtf8("apikey"))
        self.progressBar = QtGui.QProgressBar(self.main)
        self.progressBar.setGeometry(QtCore.QRect(5, 230, 421, 23))
        self.progressBar.setProperty(_fromUtf8("value"), 0)
        self.progressBar.setObjectName(_fromUtf8("progressBar"))
        self.start_button = QtGui.QPushButton(self.main)
        self.start_button.setGeometry(QtCore.QRect(430, 230, 80, 23))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.start_button.sizePolicy().hasHeightForWidth())
        self.start_button.setSizePolicy(sizePolicy)
        self.start_button.setObjectName(_fromUtf8("start_button"))
        self.options_box = QtGui.QGroupBox(self.main)
        self.options_box.setGeometry(QtCore.QRect(430, 110, 165, 61))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.options_box.sizePolicy().hasHeightForWidth())
        self.options_box.setSizePolicy(sizePolicy)
        self.options_box.setObjectName(_fromUtf8("options_box"))
        self.exp = QtGui.QCheckBox(self.options_box)
        self.exp.setGeometry(QtCore.QRect(10, 20, 141, 16))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.exp.sizePolicy().hasHeightForWidth())
        self.exp.setSizePolicy(sizePolicy)
        self.exp.setChecked(True)
        self.exp.setObjectName(_fromUtf8("exp"))
        self.done = QtGui.QCheckBox(self.options_box)
        self.done.setGeometry(QtCore.QRect(10, 40, 141, 16))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.done.sizePolicy().hasHeightForWidth())
        self.done.setSizePolicy(sizePolicy)
        self.done.setChecked(True)
        self.done.setObjectName(_fromUtf8("done"))
        self.scapth_box = QtGui.QGroupBox(self.main)
        self.scapth_box.setGeometry(QtCore.QRect(430, 170, 165, 51))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.scapth_box.sizePolicy().hasHeightForWidth())
        self.scapth_box.setSizePolicy(sizePolicy)
        self.scapth_box.setObjectName(_fromUtf8("scapth_box"))
        self.files_button = QtGui.QPushButton(self.scapth_box)
        self.files_button.setGeometry(QtCore.QRect(10, 20, 72, 23))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.files_button.sizePolicy().hasHeightForWidth())
        self.files_button.setSizePolicy(sizePolicy)
        self.files_button.setObjectName(_fromUtf8("files_button"))
        self.folder_button = QtGui.QPushButton(self.scapth_box)
        self.folder_button.setGeometry(QtCore.QRect(85, 20, 72, 23))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.folder_button.sizePolicy().hasHeightForWidth())
        self.folder_button.setSizePolicy(sizePolicy)
        self.folder_button.setObjectName(_fromUtf8("folder_button"))
        self.datatable = QtGui.QTableWidget(self.main)
        self.datatable.setGeometry(QtCore.QRect(5, 10, 421, 211))
        self.datatable.setObjectName(_fromUtf8("datatable"))
        self.datatable.setColumnCount(3)
        self.datatable.setRowCount(0)
        item = QtGui.QTableWidgetItem()
        self.datatable.setHorizontalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.datatable.setHorizontalHeaderItem(1, item)
        item = QtGui.QTableWidgetItem()
        self.datatable.setHorizontalHeaderItem(2, item)
        self.stop_button = QtGui.QPushButton(self.main)
        self.stop_button.setGeometry(QtCore.QRect(515, 230, 80, 23))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.stop_button.sizePolicy().hasHeightForWidth())
        self.stop_button.setSizePolicy(sizePolicy)
        self.stop_button.setObjectName(_fromUtf8("stop_button"))
        self.groupBox = QtGui.QGroupBox(self.main)
        self.groupBox.setGeometry(QtCore.QRect(5, 259, 591, 135))
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.groupBox.sizePolicy().hasHeightForWidth())
        self.groupBox.setSizePolicy(sizePolicy)
        self.groupBox.setObjectName(_fromUtf8("groupBox"))
        self.ed2k_export = QtGui.QTextBrowser(self.groupBox)
        self.ed2k_export.setGeometry(QtCore.QRect(7, 17, 577, 111))
        self.ed2k_export.setObjectName(_fromUtf8("ed2k_export"))
        MainWindow.setCentralWidget(self.main)
 
        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
 
    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "Avdump2", None, QtGui.QApplication.UnicodeUTF8))
        self.username_box.setTitle(QtGui.QApplication.translate("MainWindow", "Username", None, QtGui.QApplication.UnicodeUTF8))
        self.api_box.setTitle(QtGui.QApplication.translate("MainWindow", "Api-key", None, QtGui.QApplication.UnicodeUTF8))
        self.start_button.setText(QtGui.QApplication.translate("MainWindow", "Start", None, QtGui.QApplication.UnicodeUTF8))
        self.options_box.setTitle(QtGui.QApplication.translate("MainWindow", "Optionen", None, QtGui.QApplication.UnicodeUTF8))
        self.exp.setText(QtGui.QApplication.translate("MainWindow", "export ed2k links", None, QtGui.QApplication.UnicodeUTF8))
        self.done.setText(QtGui.QApplication.translate("MainWindow", "ignore already scanned", None, QtGui.QApplication.UnicodeUTF8))
        self.scapth_box.setTitle(QtGui.QApplication.translate("MainWindow", "Files/Folder to process", None, QtGui.QApplication.UnicodeUTF8))
        self.files_button.setText(QtGui.QApplication.translate("MainWindow", "Files", None, QtGui.QApplication.UnicodeUTF8))
        self.folder_button.setText(QtGui.QApplication.translate("MainWindow", "Folder", None, QtGui.QApplication.UnicodeUTF8))
        self.datatable.horizontalHeaderItem(0).setText(QtGui.QApplication.translate("MainWindow", "path", None, QtGui.QApplication.UnicodeUTF8))
        self.datatable.horizontalHeaderItem(1).setText(QtGui.QApplication.translate("MainWindow", "filename", None, QtGui.QApplication.UnicodeUTF8))
        self.datatable.horizontalHeaderItem(2).setText(QtGui.QApplication.translate("MainWindow", "status", None, QtGui.QApplication.UnicodeUTF8))
        self.stop_button.setText(QtGui.QApplication.translate("MainWindow", "Stop", None, QtGui.QApplication.UnicodeUTF8))
        self.groupBox.setTitle(QtGui.QApplication.translate("MainWindow", "ED2k-Export", None, QtGui.QApplication.UnicodeUTF8))
</pre>
 
===Wrapper module for subprocess by rar===
<pre  style="font-size: 60%;">
import subprocess
from subprocess import call, PIPE, STDOUT, list2cmdline, mswindows
import ctypes
import ctypes.wintypes
CreateProcessW = ctypes.windll.kernel32.CreateProcessW
CloseHandle = ctypes.windll.kernel32.CloseHandle
 
__all__ = ["Popen", "PIPE", "STDOUT", "call"]
 
class STARTUPINFOW(ctypes.Structure):
_fields_ = (("cb", ctypes.wintypes.DWORD), # should init to 17*4 maybe?
("lpReserved", ctypes.wintypes.LPWSTR),
("lpDesktop", ctypes.wintypes.LPWSTR),
("lpTitle", ctypes.wintypes.LPWSTR),
("dwX", ctypes.wintypes.DWORD),
("dwY", ctypes.wintypes.DWORD),
("dwXSize", ctypes.wintypes.DWORD),
("dwYSize", ctypes.wintypes.DWORD),
("dwXCountChars", ctypes.wintypes.DWORD),
("dwYCountChars", ctypes.wintypes.DWORD),
("dwFillAttribute", ctypes.wintypes.DWORD),
("dwFlags", ctypes.wintypes.DWORD),
("wShowWindow", ctypes.wintypes.WORD),
("cbReserved2", ctypes.wintypes.WORD),
("lpReserved2", ctypes.wintypes.LPSTR), # actually LPBYTE
("hStdInput", ctypes.wintypes.HANDLE),
("hStdOutput", ctypes.wintypes.HANDLE),
("hStdError", ctypes.wintypes.HANDLE))
 
class PROCESS_INFORMATION(ctypes.Structure):
_fields_ = (("hProcess", ctypes.wintypes.HANDLE),
("hThread", ctypes.wintypes.HANDLE),
("dwProcessId", ctypes.wintypes.DWORD),
("dwThreadId", ctypes.wintypes.DWORD))
 
if mswindows:
class Popen(subprocess.Popen):
def _execute_child(self, args, executable, preexec_fn, close_fds,
cwd, env, universal_newlines,
startupinfo, creationflags, shell,
p2cread, p2cwrite,
c2pread, c2pwrite,
errread, errwrite):
 
if not isinstance(args, basestring):
args = list2cmdline(args)
if not isinstance(args, unicode):
subprocess.Popen._execute_child(self, args, executable,
preexec_fn, close_fds, cwd, env, universal_newlines,
startupinfo, creationflags, shell, p2cread, p2cwrite,
c2pread, c2pwrite, errread, errwrite)
return
 
if startupinfo == None:
startupinfo = STARTUPINFOW()
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess._subprocess.SW_HIDE
else:
raise NotImplementedError("Can't pass startup stuff")
if not None in (p2cread, c2pwrite, errwrite):
raise NotImplementedError("Can't pass file object bits")
 
if shell:
raise NotImplementedError("Can't pick your own shell for unicode args")
margs = ctypes.create_unicode_buffer(args)
processinfo = PROCESS_INFORMATION()
 
CreateProcessW(executable, margs,
None, None,
1,
creationflags,
env, cwd,
ctypes.byref(startupinfo), ctypes.byref(processinfo))
hp, ht, pid, tid = (processinfo.hProcess, processinfo.hThread,
processinfo.dwProcessId, processinfo.dwThreadId)
# can't wrap this as a _subprocess_handle so scuppered, need sp_handle_new()
self._handle = hp
self.pid = pid
CloseHandle(ht) # ht.Close()
else:
Popen = subprocess.Popen
</pre>


[[Category:Avdump]]
[[Category:Avdump]]

Navigation menu

MediaWiki spam blocked by CleanTalk.