def main(): try: parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument("-w", "--webpath", help = "web path to XML file", action = "store_true") group.add_argument("-l", "--localpath", help = "local path to XML file/ directory", type = str , choices = ['f','d']) parser.add_argument ("-v", "--verbose", action="store_true", help="verbose output (i.e., debug logging") parser.add_argument("-p", "--path", help = "specify path", type = str) # parser.add_argument("-n", "--numdoc", help = "specify no of documents", type = int, default = -1) args = parser.parse_args() if args.verbose: log.basicConfig(filename=DEFAULTOUTPATH, level=log.DEBUG) else: log.basicConfig(filename=DEFAULTOUTPATH, level=log.INFO) x = ParseXML() z = CreateNewZotero() if(args.webpath): y = x.extractElementsFromURL(args.path) z.createItem(y) else: if(args.localpath == 'f'): y = x.extractElementsFromFile(args.path) z.createItem(y) else: log.debug('Reading atom XMLs in dir: %s' % args.path) parseDirectory(args.path) except KeyboardInterrupt, e: # Ctrl-C raise e
def parseDirectory(path): log.info('Parsing directory %s' % path) x = ParseXML() items = glob.glob(path + '/*-atom.xml') for i in items: # if i not in procFilesList: log.info('Now parsing:%s' % i) y = x.extractElementsFromFile(i) z = CreateNewZotero() z.createItem(y) # else: log.info('Already processed file:%s' % i) print 'Already processed file:'+i
def main(): try: parser = argparse.ArgumentParser() group = parser.add_mutually_exclusive_group() group.add_argument("-w", "--webpath", help="web path to XML file", action="store_true") group.add_argument("-l", "--localpath", help="local path to XML file/ directory", type=str, choices=['f', 'd']) parser.add_argument("-v", "--verbose", action="store_true", help="verbose output (i.e., debug logging") parser.add_argument("-p", "--path", help="specify path", type=str) # parser.add_argument("-n", "--numdoc", help = "specify no of documents", type = int, default = -1) args = parser.parse_args() if args.verbose: log.basicConfig(filename=DEFAULTOUTPATH, level=log.DEBUG) else: log.basicConfig(filename=DEFAULTOUTPATH, level=log.INFO) x = ParseXML() z = CreateNewZotero() if (args.webpath): y = x.extractElementsFromURL(args.path) z.createItem(y) else: if (args.localpath == 'f'): y = x.extractElementsFromFile(args.path) z.createItem(y) else: log.debug('Reading atom XMLs in dir: %s' % args.path) parseDirectory(args.path) except KeyboardInterrupt, e: # Ctrl-C raise e
def parseDirectory(path): log.info('Parsing directory %s' % path) x = ParseXML() items = glob.glob(path + '/*-atom.xml') f = open('procsd_files.txt', 'a') for i in items: if i not in procFilesList: log.info('Now parsing:%s' % i) try: y = x.extractElementsFromFile(i) z = CreateNewZotero() z.createItem(y) f.write(str(i)) f.write('\n') except UnicodeEncodeError: pass except Exception: f.close() else: log.info('Already processed file:%s' % i) print 'Already processed file:' + i
def generateTrace(self): numTestCase = int(self.taskSetting['monkeyLength']) / int(self.taskSetting['traceLength']) traceLength = int(self.taskSetting["traceLength"]) sleepTime = int(self.taskSetting["sleepTime"]) #record start file = open('./state/trace.txt', 'w') file.write('********** start **********' + '\n') file.close for i in xrange(numTestCase): adbList = [] isPass = True if i != 0: self.adb.restartAPP() time.sleep(sleepTime) for j in xrange(traceLength): self.adb.clearLogcat() print '-------------------------------------------------------' print 'testcase: ' + str(i) print 'tracelength: ' + str(j) self.adb.uiDump() self.adb.screencapDump() parseXML = ParseXML('0.xml') xml = parseXML.readTree() clickableButtonList = parseXML.checkClickableButton(xml) computerVision = ComputerVision('0.xml', '0.png', clickableButtonList, self.adb.appPackageName) computerVision.drawBounds() rAdClickableButtonLlist = computerVision.drawAdBounds() if self.taskSetting["algorithm"] == "monkeyCV": from TestCaseGenerator import Monkey gen = Monkey() adFlag, adBounds = computerVision.checkInterstitial() #clickableCvButtonList = computerVision.findContoursForNoClickable(clickableButtonList) clickableCvButtonList = computerVision.findContoursForNoClickable(rAdClickableButtonLlist, self.taskSetting["ROI"]) testInput = gen.getTestInput(clickableCvButtonList) if testInput == 'empty': adbList.append('adb -s ' + str(self.adb.serialNumber) + ' shell input ' + 'keyevent 4') self.adb.adbExecute('keyevent', 0, 0) else: #if adFlag == True and len(adBounds) > 0: try: if len(adBounds) > 0: inputX = (int(adBounds[0]) + int(adBounds[2])) / 2 inputY = (int(adBounds[1]) + int(adBounds[3])) / 2 else: inputX = (int(testInput[0]) + int(testInput[2])) / 2 inputY = (int(testInput[1]) + int(testInput[3])) / 2 except ValueError: print 'ValueError' time.sleep(sleepTime) try: if clickableButtonList[0][4] == self.adb.appPackageName: #computerVision.findContoursTest(clickableButtonList) computerVision.compareState() num = random.randint(0,99) if num <= 10: adbList.append('adb -s ' + str(self.adb.serialNumber) + ' shell input ' + 'keyevent 4') self.adb.adbExecute('keyevent', inputX, inputY) else: adbList.append('adb -s ' + str(self.adb.serialNumber) + ' shell input ' + 'tap ' + str(inputX) + ' ' + str(inputY)) self.adb.adbExecute('click', inputX, inputY) else: adbList.append('adb -s ' + str(self.adb.serialNumber) + " shell am force-stop " + str(self.adb.appPackageName)) adbList.append('adb -s ' + str(self.adb.serialNumber) + " shell am start " + str(self.adb.appPackageName) + '/' + str(self.adb.firstActivityName)) self.adb.restartAPP() except IndexError: print 'IndexError' time.sleep(sleepTime) elif self.taskSetting["algorithm"] == "monkeyXML": from TestCaseGenerator import Monkey gen = Monkey() testInput = gen.getTestInput(clickableButtonList) try : inputX = (int(testInput[0]) + int(testInput[2])) / 2 inputY = (int(testInput[1]) + int(testInput[3])) / 2 except ValueError: print 'ValueError' time.sleep(sleepTime) try: if clickableButtonList[0][4] == self.adb.appPackageName: num = random.randint(0,99) if num <= 10: adbList.append('adb -s ' + str(self.adb.serialNumber) + ' shell input ' + 'keyevent 4') self.adb.adbExecute('keyevent', inputX, inputY) else: adbList.append('adb -s ' + str(self.adb.serialNumber) + ' shell input ' + 'tap ' + str(inputX) + ' ' + str(inputY)) self.adb.adbExecute('click', inputX, inputY) else: adbList.append('adb -s ' + str(self.adb.serialNumber) + " shell am force-stop " + str(self.adb.appPackageName)) adbList.append('adb -s ' + str(self.adb.serialNumber) + " shell am start " + str(self.adb.appPackageName) + '/' + str(self.adb.firstActivityName)) self.adb.restartAPP() except IndexError: print 'IndexError' time.sleep(sleepTime) time.sleep(sleepTime) #check code stack and log files self.adb.generateLog() csResult = self.checkCodeStack('./state/log.txt') if csResult != "pass": isPass = False adbList.append(str(csResult)) break if self.taskSetting["instrument"] == "True": lc.calculate_line_coverage(self.adb.appPackageName) else: pass print adbList #End of a trace, and start writing trace.txt if isPass == True: print 'testcase: pass' file = open('./state/trace.txt', 'a') file.write('---------- testcase ' + str(i) + ' pass----------' + '\n') for adb in adbList: file.write(str(adb) + '\n') file.close else: print 'testcase: fail' file.write('---------- testcase ' + str(i) + ' fail----------' + '\n') file = open('./state/trace.txt', 'a') for adb in adbList: file.write(str(adb) + '\n') file.close
class Keyboard(gtk.Frame): __gtype_name__ = 'Keyboard' SPACING = 6 def __init__(self, layout): gtk.Frame.__init__(self) self.connect("expose_event", self.expose) # This is a GenericLayout object, created in KeyboardLayoutEditor. self.xmllayout = layout self.layoutcode = '' self.layoutvariant = '' self.layoutcountry = '' self.layoutname = '' KeyDict.set() # Fill in the KeyDict structure with xml branches for key in KeyDict.Keys.keys(): if self.xmllayout.exists_tokenkey(key): print "Key", key, "already exists in xmllayout." if KeyDict.Keys[key].xmlbranch == None: print "Key", key, "was not set, setting now" elif KeyDict.Keys[key].xmlbranch != xmllayout.return_tokenkey(key): print "Key", key, "already set to something..." else: KeyDict.Keys[key].xmlbranch = xmllayout.create_tokenkey(key) elif self.xmllayout.create_tokenkey(key) != None: pass #print "Added", key else: SystemError("Unable to add " + key) #print self.xmllayout.tostring() self.set_label("") self.set_shadow_type(gtk.SHADOW_NONE) __row1 = ("ESC" , "FK01", "FK02", "FK03", "FK04", "FK05", "FK06", "FK07", "FK08", "FK09", "FK10", "FK11", "FK12") __row1_esc = ("ESC",) __row1_f14 = ("FK01", "FK02", "FK03", "FK04") __row1_f58 = ("FK05", "FK06", "FK07", "FK08") __row1_f92 = ("FK09", "FK10", "FK11", "FK12") __row2 = ("TLDE", "AE01", "AE02", "AE03", "AE04", "AE05", "AE06", "AE07", "AE08", "AE09", "AE10", "AE11", "AE12", "BKSP") __row3 = ("TAB" , "AD01", "AD02", "AD03", "AD04", "AD05", "AD06", "AD07", "AD08", "AD09", "AD10", "AD11", "AD12", "BKSL") __row4 = ("CAPS", "AC01", "AC02", "AC03", "AC04", "AC05", "AC06", "AC07", "AC08", "AC09", "AC10", "AC11", "RTRN") __row5 = ("LFSH", "LSGT", "AB01", "AB02", "AB03", "AB04", "AB05", "AB06", "AB07", "AB08", "AB09", "AB10", "RTSH") __row6 = ("LCTL", "LWIN", "LALT", "SPCE", "RALT", "RWIN", "MENU", "RCTL") vbox = gtk.VBox(False, Keyboard.SPACING) hbox1 = gtk.HBox(False, Keyboard.SPACING) hbox2 = gtk.HBox(False, Keyboard.SPACING) hbox3 = gtk.HBox(False, Keyboard.SPACING) hbox4 = gtk.HBox(False, Keyboard.SPACING) hbox5 = gtk.HBox(False, Keyboard.SPACING) hbox6 = gtk.HBox(False, Keyboard.SPACING) hboxtop_esc = gtk.HBox(False, Keyboard.SPACING) hboxtop_f14 = gtk.HBox(False, Keyboard.SPACING) hboxtop_f58 = gtk.HBox(False, Keyboard.SPACING) hboxtop_f92 = gtk.HBox(False, Keyboard.SPACING) aligntop_esc = gtk.Alignment( 0, 0, .1, 1) aligntop_f14 = gtk.Alignment(.1, 0, .5, 1) aligntop_f58 = gtk.Alignment(.8, 0, .5, 1) aligntop_f92 = gtk.Alignment( 1, 0, .4, 1) aligntop_esc.add(hboxtop_esc) aligntop_f14.add(hboxtop_f14) aligntop_f58.add(hboxtop_f58) aligntop_f92.add(hboxtop_f92) hbox1.pack_start(aligntop_esc, expand=True, fill=True) hbox1.pack_start(aligntop_f14, expand=True, fill=True) hbox1.pack_start(aligntop_f58, expand=True, fill=True) hbox1.pack_start(aligntop_f92, expand=True, fill=True) vbox.pack_start(hbox1, expand=True, fill=True) vbox.pack_start(hbox2, expand=True, fill=True) vbox.pack_start(hbox3, expand=True, fill=True) vbox.pack_start(hbox4, expand=True, fill=True) vbox.pack_start(hbox5, expand=True, fill=True) vbox.pack_start(hbox6, expand=True, fill=True) for item in __row1_esc: hboxtop_esc.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row1_f14: hboxtop_f14.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row1_f58: hboxtop_f58.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row1_f92: hboxtop_f92.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row2: hbox2.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row3: hbox3.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row4: hbox4.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row5: hbox5.pack_start(KeyDict.Keys[item], expand=True, fill=True) for item in __row6: hbox6.pack_start(KeyDict.Keys[item], expand=True, fill=True) self.add(vbox) def draw(self, context): pass def expose(self, widget, event): self.context = widget.window.cairo_create() # set a clip region for the expose event self.context.set_source_rgb(0.81, 0.84, 0.81) self.context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) self.context.fill_preserve() self.context.clip() self.draw(self.context) return False def receiveCallback(widget, context, x, y, selection, targetType, time): print "Keyboard: Received a callback for", selection, "at", x, y, "at", time def redraw(self): for keycode in KeyDict.Keys.keys(): KeyDict.Keys[keycode].key.extract_display_keyvalues() KeyDict.Keys[keycode].key.redraw() def save(self, layout_file): try: fout = open(layout_file, "w") except IOError, e: return False self.gl_layout = GenericLayout.GenericLayout() newxml = self.gl_layout.create_layout(self.layoutcode, self.layoutvariant, self.layoutcountry, self.layoutname, KeyDict.Keys) fout.write(Common.layout_preamble) ParseXML(newxml, fout) fout.close() return True