Best Python code snippet using toolium_python
__init__.py
Source:__init__.py
...335 'Cortex-M7FD': {'mcpu': 'cortex-m7', 'fpu_unit': 'fpv5d16'},336 'Cortex-A9': {'mcpu': 'cortex-a9', 'fpu_unit': 'vfpv3'}337 }338 # Remove options that are supplied by CDT339 self.remove_option(flags['common_flags'], '-c')340 self.remove_option(flags['common_flags'], '-MMD')341 # As 'plan B', get the CPU from the target definition.342 core = self.toolchain.target.core343 opts['common']['arm.target.family'] = None344 # cortex-m0, cortex-m0-small-multiply, cortex-m0plus,345 # cortex-m0plus-small-multiply, cortex-m1, cortex-m1-small-multiply,346 # cortex-m3, cortex-m4, cortex-m7.347 str = self.find_options(flags['common_flags'], '-mcpu=')348 if str != None:349 opts['common']['arm.target.family'] = str[len('-mcpu='):]350 self.remove_option(flags['common_flags'], str)351 self.remove_option(flags['ld_flags'], str)352 else:353 if core not in MCPUS:354 raise NotSupportedException(355 'Target core {0} not supported.'.format(core))356 opts['common']['arm.target.family'] = MCPUS[core]['mcpu']357 opts['common']['arm.target.arch'] = 'none'358 str = self.find_options(flags['common_flags'], '-march=')359 arch = str[len('-march='):]360 archs = {'armv6-m': 'armv6-m', 'armv7-m': 'armv7-m', 'armv7-a': 'armv7-a'}361 if arch in archs:362 opts['common']['arm.target.arch'] = archs[arch]363 self.remove_option(flags['common_flags'], str)364 opts['common']['arm.target.instructionset'] = 'thumb'365 if '-mthumb' in flags['common_flags']:366 self.remove_option(flags['common_flags'], '-mthumb')367 self.remove_option(flags['ld_flags'], '-mthumb')368 elif '-marm' in flags['common_flags']:369 opts['common']['arm.target.instructionset'] = 'arm'370 self.remove_option(flags['common_flags'], '-marm')371 self.remove_option(flags['ld_flags'], '-marm')372 opts['common']['arm.target.thumbinterwork'] = False373 if '-mthumb-interwork' in flags['common_flags']:374 opts['common']['arm.target.thumbinterwork'] = True375 self.remove_option(flags['common_flags'], '-mthumb-interwork')376 opts['common']['arm.target.endianness'] = None377 if '-mlittle-endian' in flags['common_flags']:378 opts['common']['arm.target.endianness'] = 'little'379 self.remove_option(flags['common_flags'], '-mlittle-endian')380 elif '-mbig-endian' in flags['common_flags']:381 opts['common']['arm.target.endianness'] = 'big'382 self.remove_option(flags['common_flags'], '-mbig-endian')383 opts['common']['arm.target.fpu.unit'] = None384 # default, fpv4spd16, fpv5d16, fpv5spd16385 str = self.find_options(flags['common_flags'], '-mfpu=')386 if str != None:387 fpu = str[len('-mfpu='):]388 fpus = {389 'fpv4-sp-d16': 'fpv4spd16',390 'fpv5-d16': 'fpv5d16',391 'fpv5-sp-d16': 'fpv5spd16'392 }393 if fpu in fpus:394 opts['common']['arm.target.fpu.unit'] = fpus[fpu]395 self.remove_option(flags['common_flags'], str)396 self.remove_option(flags['ld_flags'], str)397 if opts['common']['arm.target.fpu.unit'] == None:398 if core not in MCPUS:399 raise NotSupportedException(400 'Target core {0} not supported.'.format(core))401 if MCPUS[core]['fpu_unit']:402 opts['common'][403 'arm.target.fpu.unit'] = MCPUS[core]['fpu_unit']404 # soft, softfp, hard.405 str = self.find_options(flags['common_flags'], '-mfloat-abi=')406 if str != None:407 opts['common']['arm.target.fpu.abi'] = str[408 len('-mfloat-abi='):]409 self.remove_option(flags['common_flags'], str)410 self.remove_option(flags['ld_flags'], str)411 opts['common']['arm.target.unalignedaccess'] = None412 if '-munaligned-access' in flags['common_flags']:413 opts['common']['arm.target.unalignedaccess'] = 'enabled'414 self.remove_option(flags['common_flags'], '-munaligned-access')415 elif '-mno-unaligned-access' in flags['common_flags']:416 opts['common']['arm.target.unalignedaccess'] = 'disabled'417 self.remove_option(flags['common_flags'], '-mno-unaligned-access')418 # Default optimisation level for Release.419 opts['common']['optimization.level'] = '-Os'420 # If the project defines an optimisation level, it is used421 # only for the Release configuration, the Debug one used '-Og'.422 str = self.find_options(flags['common_flags'], '-O')423 if str != None:424 levels = {425 '-O0': 'none', '-O1': 'optimize', '-O2': 'more',426 '-O3': 'most', '-Os': 'size', '-Og': 'debug'427 }428 if str in levels:429 opts['common']['optimization.level'] = levels[str]430 self.remove_option(flags['common_flags'], str)431 include_files = []432 for all_flags in [flags['common_flags'], flags['c_flags'], flags['cxx_flags']]:433 while '-include' in all_flags:434 ix = all_flags.index('-include')435 str = all_flags[ix + 1]436 if str not in include_files:437 include_files.append(str)438 self.remove_option(all_flags, '-include')439 self.remove_option(all_flags, str)440 opts['common']['include_files'] = include_files441 if '-ansi' in flags['c_flags']:442 opts['c']['compiler.std'] = '-ansi'443 self.remove_option(flags['c_flags'], str)444 else:445 str = self.find_options(flags['c_flags'], '-std')446 std = str[len('-std='):]447 c_std = {448 'c90': 'c90', 'c89': 'c90', 'gnu90': 'gnu90', 'gnu89': 'gnu90',449 'c99': 'c99', 'c9x': 'c99', 'gnu99': 'gnu99', 'gnu9x': 'gnu98',450 'c11': 'c11', 'c1x': 'c11', 'gnu11': 'gnu11', 'gnu1x': 'gnu11'451 }452 if std in c_std:453 opts['c']['compiler.std'] = c_std[std]454 self.remove_option(flags['c_flags'], str)455 if '-ansi' in flags['cxx_flags']:456 opts['cpp']['compiler.std'] = '-ansi'457 self.remove_option(flags['cxx_flags'], str)458 else:459 str = self.find_options(flags['cxx_flags'], '-std')460 std = str[len('-std='):]461 cpp_std = {462 'c++98': 'cpp98', 'c++03': 'cpp98',463 'gnu++98': 'gnucpp98', 'gnu++03': 'gnucpp98',464 'c++0x': 'cpp0x', 'gnu++0x': 'gnucpp0x',465 'c++11': 'cpp11', 'gnu++11': 'gnucpp11',466 'c++1y': 'cpp1y', 'gnu++1y': 'gnucpp1y',467 'c++14': 'cpp14', 'gnu++14': 'gnucpp14',468 'c++1z': 'cpp1z', 'gnu++1z': 'gnucpp1z',469 }470 if std in cpp_std:471 opts['cpp']['compiler.std'] = cpp_std[std]472 self.remove_option(flags['cxx_flags'], str)473 # Common optimisation options.474 optimization_options = {475 '-fmessage-length=0': 'optimization.messagelength',476 '-fsigned-char': 'optimization.signedchar',477 '-ffunction-sections': 'optimization.functionsections',478 '-fdata-sections': 'optimization.datasections',479 '-fno-common': 'optimization.nocommon',480 '-fno-inline-functions': 'optimization.noinlinefunctions',481 '-ffreestanding': 'optimization.freestanding',482 '-fno-builtin': 'optimization.nobuiltin',483 '-fsingle-precision-constant': 'optimization.spconstant',484 '-fPIC': 'optimization.PIC',485 '-fno-move-loop-invariants': 'optimization.nomoveloopinvariants',486 }487 for option in optimization_options:488 opts['common'][optimization_options[option]] = False489 if option in flags['common_flags']:490 opts['common'][optimization_options[option]] = True491 self.remove_option(flags['common_flags'], option)492 # Common warning options.493 warning_options = {494 '-fsyntax-only': 'warnings.syntaxonly',495 '-pedantic': 'warnings.pedantic',496 '-pedantic-errors': 'warnings.pedanticerrors',497 '-w': 'warnings.nowarn',498 '-Wunused': 'warnings.unused',499 '-Wuninitialized': 'warnings.uninitialized',500 '-Wall': 'warnings.allwarn',501 '-Wextra': 'warnings.extrawarn',502 '-Wmissing-declarations': 'warnings.missingdeclaration',503 '-Wconversion': 'warnings.conversion',504 '-Wpointer-arith': 'warnings.pointerarith',505 '-Wpadded': 'warnings.padded',506 '-Wshadow': 'warnings.shadow',507 '-Wlogical-op': 'warnings.logicalop',508 '-Waggregate-return': 'warnings.agreggatereturn',509 '-Wfloat-equal': 'warnings.floatequal',510 '-Werror': 'warnings.toerrors',511 }512 for option in warning_options:513 opts['common'][warning_options[option]] = False514 if option in flags['common_flags']:515 opts['common'][warning_options[option]] = True516 self.remove_option(flags['common_flags'], option)517 # Common debug options.518 debug_levels = {519 '-g': 'default',520 '-g1': 'minimal',521 '-g3': 'max',522 }523 opts['common']['debugging.level'] = 'none'524 for option in debug_levels:525 if option in flags['common_flags']:526 opts['common'][527 'debugging.level'] = debug_levels[option]528 self.remove_option(flags['common_flags'], option)529 debug_formats = {530 '-ggdb': 'gdb',531 '-gstabs': 'stabs',532 '-gstabs+': 'stabsplus',533 '-gdwarf-2': 'dwarf2',534 '-gdwarf-3': 'dwarf3',535 '-gdwarf-4': 'dwarf4',536 '-gdwarf-5': 'dwarf5',537 }538 opts['common']['debugging.format'] = ''539 for option in debug_levels:540 if option in flags['common_flags']:541 opts['common'][542 'debugging.format'] = debug_formats[option]543 self.remove_option(flags['common_flags'], option)544 opts['common']['debugging.prof'] = False545 if '-p' in flags['common_flags']:546 opts['common']['debugging.prof'] = True547 self.remove_option(flags['common_flags'], '-p')548 opts['common']['debugging.gprof'] = False549 if '-pg' in flags['common_flags']:550 opts['common']['debugging.gprof'] = True551 self.remove_option(flags['common_flags'], '-gp')552 # Assembler options.553 opts['as']['usepreprocessor'] = False554 while '-x' in flags['asm_flags']:555 ix = flags['asm_flags'].index('-x')556 str = flags['asm_flags'][ix + 1]557 if str == 'assembler-with-cpp':558 opts['as']['usepreprocessor'] = True559 else:560 # Collect all other assembler options.561 opts['as']['other'] += ' -x ' + str562 self.remove_option(flags['asm_flags'], '-x')563 self.remove_option(flags['asm_flags'], 'assembler-with-cpp')564 opts['as']['nostdinc'] = False565 if '-nostdinc' in flags['asm_flags']:566 opts['as']['nostdinc'] = True567 self.remove_option(flags['asm_flags'], '-nostdinc')568 opts['as']['verbose'] = False569 if '-v' in flags['asm_flags']:570 opts['as']['verbose'] = True571 self.remove_option(flags['asm_flags'], '-v')572 # C options.573 opts['c']['nostdinc'] = False574 if '-nostdinc' in flags['c_flags']:575 opts['c']['nostdinc'] = True576 self.remove_option(flags['c_flags'], '-nostdinc')577 opts['c']['verbose'] = False578 if '-v' in flags['c_flags']:579 opts['c']['verbose'] = True580 self.remove_option(flags['c_flags'], '-v')581 warning_options = {582 '-Wmissing-prototypes': 'warnings.missingprototypes',583 '-Wstrict-prototypes': 'warnings.strictprototypes',584 '-Wbad-function-cast': 'warnings.badfunctioncast',585 }586 for option in warning_options:587 opts['c'][warning_options[option]] = False588 if option in flags['common_flags']:589 opts['c'][warning_options[option]] = True590 self.remove_option(flags['common_flags'], option)591 # C++ options.592 opts['cpp']['nostdinc'] = False593 if '-nostdinc' in flags['cxx_flags']:594 opts['cpp']['nostdinc'] = True595 self.remove_option(flags['cxx_flags'], '-nostdinc')596 opts['cpp']['nostdincpp'] = False597 if '-nostdinc++' in flags['cxx_flags']:598 opts['cpp']['nostdincpp'] = True599 self.remove_option(flags['cxx_flags'], '-nostdinc++')600 optimization_options = {601 '-fno-exceptions': 'optimization.noexceptions',602 '-fno-rtti': 'optimization.nortti',603 '-fno-use-cxa-atexit': 'optimization.nousecxaatexit',604 '-fno-threadsafe-statics': 'optimization.nothreadsafestatics',605 }606 for option in optimization_options:607 opts['cpp'][optimization_options[option]] = False608 if option in flags['cxx_flags']:609 opts['cpp'][optimization_options[option]] = True610 self.remove_option(flags['cxx_flags'], option)611 if option in flags['common_flags']:612 opts['cpp'][optimization_options[option]] = True613 self.remove_option(flags['common_flags'], option)614 warning_options = {615 '-Wabi': 'warnabi',616 '-Wctor-dtor-privacy': 'warnings.ctordtorprivacy',617 '-Wnoexcept': 'warnings.noexcept',618 '-Wnon-virtual-dtor': 'warnings.nonvirtualdtor',619 '-Wstrict-null-sentinel': 'warnings.strictnullsentinel',620 '-Wsign-promo': 'warnings.signpromo',621 '-Weffc++': 'warneffc',622 }623 for option in warning_options:624 opts['cpp'][warning_options[option]] = False625 if option in flags['cxx_flags']:626 opts['cpp'][warning_options[option]] = True627 self.remove_option(flags['cxx_flags'], option)628 if option in flags['common_flags']:629 opts['cpp'][warning_options[option]] = True630 self.remove_option(flags['common_flags'], option)631 opts['cpp']['verbose'] = False632 if '-v' in flags['cxx_flags']:633 opts['cpp']['verbose'] = True634 self.remove_option(flags['cxx_flags'], '-v')635 # Linker options.636 linker_options = {637 '-nostartfiles': 'nostart',638 '-nodefaultlibs': 'nodeflibs',639 '-nostdlib': 'nostdlibs',640 }641 for option in linker_options:642 opts['ld'][linker_options[option]] = False643 if option in flags['ld_flags']:644 opts['ld'][linker_options[option]] = True645 self.remove_option(flags['ld_flags'], option)646 opts['ld']['gcsections'] = False647 if '-Wl,--gc-sections' in flags['ld_flags']:648 opts['ld']['gcsections'] = True649 self.remove_option(flags['ld_flags'], '-Wl,--gc-sections')650 opts['ld']['flags'] = []651 to_remove = []652 for opt in flags['ld_flags']:653 if opt.startswith('-Wl,--wrap,'):654 opts['ld']['flags'].append(655 '--wrap=' + opt[len('-Wl,--wrap,'):])656 to_remove.append(opt)657 for opt in to_remove:658 self.remove_option(flags['ld_flags'], opt)659 # Other tool remaining options are separated by category.660 opts['as']['otherwarnings'] = self.find_options(661 flags['asm_flags'], '-W')662 opts['c']['otherwarnings'] = self.find_options(663 flags['c_flags'], '-W')664 opts['c']['otheroptimizations'] = self.find_options(flags[665 'c_flags'], '-f')666 opts['cpp']['otherwarnings'] = self.find_options(667 flags['cxx_flags'], '-W')668 opts['cpp']['otheroptimizations'] = self.find_options(669 flags['cxx_flags'], '-f')670 # Other common remaining options are separated by category.671 opts['common']['optimization.other'] = self.find_options(672 flags['common_flags'], '-f')673 opts['common']['warnings.other'] = self.find_options(674 flags['common_flags'], '-W')675 # Remaining common flags are added to each tool.676 opts['as']['other'] += ' ' + \677 ' '.join(flags['common_flags']) + ' ' + \678 ' '.join(flags['asm_flags'])679 opts['c']['other'] += ' ' + \680 ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['c_flags'])681 opts['cpp']['other'] += ' ' + \682 ' '.join(flags['common_flags']) + ' ' + \683 ' '.join(flags['cxx_flags'])684 opts['ld']['other'] += ' ' + \685 ' '.join(flags['common_flags']) + ' ' + ' '.join(flags['ld_flags'])686 if len(self.system_libraries) > 0:687 opts['ld']['other'] += ' -Wl,--start-group '688 opts['ld'][689 'other'] += ' '.join('-l' + s for s in self.system_libraries)690 opts['ld']['other'] += ' -Wl,--end-group '691 # Strip all 'other' flags, since they might have leading spaces.692 opts['as']['other'] = opts['as']['other'].strip()693 opts['c']['other'] = opts['c']['other'].strip()694 opts['cpp']['other'] = opts['cpp']['other'].strip()695 opts['ld']['other'] = opts['ld']['other'].strip()696 @staticmethod697 def find_options(lst, option):698 tmp = [str for str in lst if str.startswith(option)]699 if len(tmp) > 0:700 return tmp[0]701 else:702 return None703 @staticmethod704 def find_options(lst, prefix):705 other = ''706 opts = [str for str in lst if str.startswith(prefix)]707 if len(opts) > 0:708 for opt in opts:709 other += ' ' + opt710 GNUARMEclipse.remove_option(lst, opt)711 return other.strip()712 @staticmethod713 def remove_option(lst, option):714 if option in lst:715 lst.remove(option)...
config.py
Source:config.py
...34 if data['mode'] == '0':35 if len(data['ip']) != 0:36 if len(data['port']) != 0:37 if int(data['port']) in range(1, 65002):38 conf.remove_option("Proxy", "socks_proxy")39 conf.remove_option("Proxy", "socks_port")40 conf.set("Proxy", "http_proxy", data['ip'])41 conf.set("Proxy", "http_port", data['port'])42 with open(os+"/conf.ini", "w", encoding="utf-8") as f:43 conf.write(f)44 else:45 return "端å£ä¸åæ³ ï¼"46 else:47 return "端å£ä¸ºç©º ï¼"48 else:49 return "代çå°å为空 ï¼"50 elif data['mode'] == '1':51 if len(data['ip']) != 0:52 if len(data['port']) != 0:53 if int(data['port']) in range(1,65002):54 regx = re.compile(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}')55 rst = regx.match(data['ip'])56 if rst is None:57 return "ipå°åæ ¼å¼ä¸æ£ç¡® ï¼"58 else:59 conf.remove_option("Proxy", "http_proxy")60 conf.remove_option("Proxy", "http_port")61 conf.set("Proxy", "socks_proxy", data['ip'])62 conf.set("Proxy", "socks_port", data['port'])63 with open(os+"/conf.ini", "w", encoding="utf-8") as f:64 conf.write(f)65 else:66 return "端å£ä¸åæ³ ï¼"67 else:68 return "端å£ä¸ºç©º ï¼"69 else:70 return "代çå°å为空 ï¼"71 else:72 try:73 conf.remove_option("Proxy", "http_proxy")74 conf.remove_option("Proxy", "http_port")75 conf.remove_option("Proxy", "socks_proxy")76 conf.remove_option("Proxy", "socks_port")77 with open(os + "/conf.ini", "w", encoding="utf-8") as f:78 conf.write(f)79 return "å·²å é¤ä»£ç ï¼"80 except Exception:81 conf.remove_option("Proxy", "socks_proxy")82 conf.remove_option("Proxy", "socks_port")83 conf.remove_option("Proxy", "http_proxy")84 conf.remove_option("Proxy", "http_port")85 with open(os + "/conf.ini", "w", encoding="utf-8") as f:86 conf.write(f)87 return "å·²å é¤ä»£ç ï¼"88 if len(data['email']) != 0:89 if len(data['key']) != 0:90 conf.remove_option("FOFA", "key")91 conf.remove_option("FOFA", "email")92 conf.set("FOFA", "key", data['key'])93 conf.set("FOFA", "email", data['email'])94 with open(os + "/conf.ini", "w", encoding="utf-8") as f:95 conf.write(f)96 else:97 return "Fofaå¯é¥ä¸ºç©º ï¼"98 else:99 return "Emailå¯é¥ä¸ºç©º ï¼"100 if len(data['email']) == 0:101 if len(data['key']) == 0:102 conf.remove_option("FOFA", "key")103 conf.remove_option("FOFA", "email")104 conf.set("FOFA", "key", data['key'])105 conf.set("FOFA", "email", data['email'])106 with open(os + "/conf.ini", "w", encoding="utf-8") as f:107 conf.write(f)108 else:109 conf.remove_option("FOFA", "key")110 conf.remove_option("FOFA", "email")111 conf.set("FOFA", "key", data['key'])112 conf.set("FOFA", "email", data['email'])113 with open(os + "/conf.ini", "w", encoding="utf-8") as f:114 conf.write(f)115 elif len(data['key']) == 0:116 if len(data['email']) != 0:117 conf.remove_option("FOFA", "key")118 conf.remove_option("FOFA", "email")119 conf.set("FOFA", "key", data['key'])120 conf.set("FOFA", "email", data['email'])121 with open(os + "/conf.ini", "w", encoding="utf-8") as f:122 conf.write(f)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!