diff options
author | Noe Rubinstein <nrubinstein@avencall.com> | 2012-07-30 19:56:09 +0200 |
---|---|---|
committer | Noe Rubinstein <nrubinstein@avencall.com> | 2012-07-30 19:56:09 +0200 |
commit | a0a5f650ffad69746cae843fb29c477675143d4a (patch) | |
tree | 75e099b479cfb9a37a76c142f3edf67267ac57ef | |
parent | 93ef5214e93d040e6f5eb065cdff5ba99060edf3 (diff) | |
parent | 512f61698e63756928d8be35dd870ddb92c0ad79 (diff) |
Merge branch 'master' of githardware:git/misc
tiuejhijjiijij
-rwxr-xr-x | filter_disasm.py | 119 | ||||
-rwxr-xr-x | pyside_gui/bouton.py | 29 | ||||
-rw-r--r-- | pyside_gui/bouton_qt.py | 36 | ||||
-rw-r--r-- | pyside_gui/bouton_qt.ui | 45 | ||||
-rw-r--r-- | stock.py | 59 |
5 files changed, 288 insertions, 0 deletions
diff --git a/filter_disasm.py b/filter_disasm.py new file mode 100755 index 0000000..96c6abc --- /dev/null +++ b/filter_disasm.py @@ -0,0 +1,119 @@ +#!/usr/bin/python + +import re +import sys +# from difflib import SequenceMatcher +from optparse import OptionParser + + +INSTRUCTION_PREFIXES = ['rep', 'repe', 'repne'] + + +def split_instr(full_instr): + """ + Given a line of assembly language (symbolic part from objdump -d), + return (instr, operands). operands can be an empty string. + """ + assert full_instr.strip() + split = full_instr.split(None, 1) + if len(split) == 1: + return (split[0], '') + start, end = split + if start in INSTRUCTION_PREFIXES: + next, end = end.split(None, 1) + start += " " + next + return (start, end) + + +def relative_only(operand): + mo = re.match(r"[0-9A-Fa-f]+ (<.*)$", operand) + return mo.group(1) if mo else operand + + +def split_filter_instr(full_instr): + mnemonic, operands = split_instr(full_instr) + return mnemonic, relative_only(operands) + + +class Func(object): + def __init__(self, name, addr): + self.name = name + self.addr = addr + self.instructions = [] + def push_line(self, line): + line = line.strip() + mo = re.match(r"([0-9A-Fa-f]+):[\t]([^\t]+)[\t](.+)$", line) + if not mo: + if not re.match(r"([0-9A-Fa-f]+):[\t]([^\t]+)$", line): + self.close() + return False + else: + return True + addr, bytes, symb = mo.groups() + instr = split_filter_instr(symb) + self.instructions.append(instr) + return True + def close(self): + while self.instructions and self.instructions[-1] == ('nop', ''): + del self.instructions[-1] + def dump(self, f): + f.write("%s %08x\n" % (self.name, self.addr)) + for instr in self.instructions: + f.write("\t%s\t%s\n" % (instr[0], instr[1])) + f.write("\n") + + +def match_func_header(line): + line = line.strip() + mo = re.match(r"([0-9A-Fa-f]{8}) <([^>]+)>:$", line) + return None if mo is None else mo.groups() + + +def load_disasm(filename): + funcs = {} # name: Func() + current = None + with open(filename) as f: + for line in f: + if current: + cont = current.push_line(line) + if not cont: + current = None + else: + fh = match_func_header(line) + if fh: + current = Func(fh[1], int(fh[0], 16)) + funcs[current.name] = current + else: + print >> sys.stderr, "Unused:", line.rstrip() + if current: + current.close() + return funcs + + +def dump_disasm(filename, funcs): + func_names = funcs.keys() + func_names.sort() + with open(filename, "w") as f: + for name in func_names: + funcs[name].dump(f) + + +def main(): + parser = OptionParser(usage="usage: %prog [options] file.disasm") + (options, args) = parser.parse_args() + if len(args) != 1: + parser.print_help() + sys.exit(1) + filename = args[0] + funcs = load_disasm(filename) + # now we are trying to be extramely lazy: + # just dump the damn files sorted and stripped, so we can try + # do diff them externally + dump_disasm(filename + ".dump", funcs) + + +if __name__ == '__main__': + main() + + +# PS: i like "extramely" diff --git a/pyside_gui/bouton.py b/pyside_gui/bouton.py new file mode 100755 index 0000000..3bb4ab4 --- /dev/null +++ b/pyside_gui/bouton.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +import sys + +from PySide.QtGui import QMainWindow, QApplication + +from bouton_qt import Ui_MainWindow + + +class MainWindow(QMainWindow, Ui_MainWindow): + def __init__(self, parent=None): + super(MainWindow, self).__init__(parent) + self.setupUi(self) + self.pushButton.clicked.connect(self.le_bouton) + def le_bouton(self): + print "bouton !" + + +def main(): + app = QApplication(sys.argv) + try: + frame = MainWindow() + frame.show() + app.exec_() + finally: + print "byebye" + + +main() diff --git a/pyside_gui/bouton_qt.py b/pyside_gui/bouton_qt.py new file mode 100644 index 0000000..869b3f2 --- /dev/null +++ b/pyside_gui/bouton_qt.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'bouton_qt.ui' +# +# Created: Tue Jun 26 11:24:53 2012 +# by: pyside-uic 0.2.13 running on PySide 1.1.1 +# +# WARNING! All changes made in this file will be lost! + +from PySide import QtCore, QtGui + +class Ui_MainWindow(object): + def setupUi(self, MainWindow): + MainWindow.setObjectName("MainWindow") + MainWindow.resize(800, 600) + self.centralwidget = QtGui.QWidget(MainWindow) + self.centralwidget.setObjectName("centralwidget") + self.pushButton = QtGui.QPushButton(self.centralwidget) + self.pushButton.setGeometry(QtCore.QRect(220, 170, 321, 211)) + self.pushButton.setObjectName("pushButton") + MainWindow.setCentralWidget(self.centralwidget) + self.menubar = QtGui.QMenuBar(MainWindow) + self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 19)) + self.menubar.setObjectName("menubar") + MainWindow.setMenuBar(self.menubar) + self.statusbar = QtGui.QStatusBar(MainWindow) + self.statusbar.setObjectName("statusbar") + MainWindow.setStatusBar(self.statusbar) + + self.retranslateUi(MainWindow) + QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def retranslateUi(self, MainWindow): + MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8)) + self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "BOUTON !!!", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/pyside_gui/bouton_qt.ui b/pyside_gui/bouton_qt.ui new file mode 100644 index 0000000..f95bde5 --- /dev/null +++ b/pyside_gui/bouton_qt.ui @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <widget class="QWidget" name="centralwidget"> + <widget class="QPushButton" name="pushButton"> + <property name="geometry"> + <rect> + <x>220</x> + <y>170</y> + <width>321</width> + <height>211</height> + </rect> + </property> + <property name="text"> + <string>BOUTON !!!</string> + </property> + </widget> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>19</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/stock.py b/stock.py new file mode 100644 index 0000000..410e16a --- /dev/null +++ b/stock.py @@ -0,0 +1,59 @@ +import sys, time +import ezodf +import pickle +from collections import OrderedDict + +def parse_file(f, sheet, keyno, fields, skip_first=1, skip_last=0): + l = [] + try: # Read EagleDbDict or create it if not present + ods = ezodf.opendoc(f) + sheet = ods.sheets[sheet] + for index in range(skip_first, sheet.nrows()-skip_last): + new = [sheet[index, keyno].value] + new.extend(sheet[index, i].value for i in fields) + l.append(new) + #print(key, Data) + except IOError as err: + print('No stockFile Named:', f) + return None + return l + +#Get Avencall stock +Stock = parse_file('../AvenCallHardwareStock.ods', 'Work', 0, (2,4)) +Quote = parse_file('/home/massoud/Projets/XiVO/Software/proto_pcbs/pcb_xioh/Ver5/EgV6-XIOHV5/BoM/Commandes/Digikey/XIOHv5-Digikey-Order-quote7081688.ods', + 'dk', 0, (3,5), skip_first=0, skip_last=2) +EagleBom = parse_file('../EagleBom.ods','BomProcess', 0, (6,5)) + +#disp_struct(Stock) +#disp_struct(Quote) + + +def join(a, b, fa, fb): + return [ (j, k) for j in a for k in b if j[fa] == k[fb] ] + +def disp_struct(s): + print(len(s), s) + +disp_struct(EagleBom) + +def disp_struct_filter(sname, filter): + print(list(k for k in sname if k[2]!= filter)) + +disp_struct_filter(EagleBom, 'digikey') +#disp_struct_filter(EagleBom, 'Farnell') + +join_eagle_quote = list((j,k) for (j,k) in join(EagleBom,Quote,1,0) if k[2]) +#disp_struct(join_eagle_quote) + +def write_result(fname, sheetname, tbl): + ods = ezodf.opendoc(fname) + for sheet in ods.sheets: + pass +# print(sheet.name) + sheet = ods.sheets[sheetname] + sheet.insert_rows(0,len(tbl)) + for i in range(len(tbl)): + sheet[i,0].set_value(tbl[i][0][1]) + ods.save() + +write_result('/home/massoud/Projets/XiVO/Software/proto_pcbs/pcb_xioh/Ver5/EgV6-XIOHV5/BoM/Commandes/Digikey/XIOHv5-Digikey-Order-quote7081688.ods','order',join_eagle_quote) |