How to use remove_file_if_exists method in locust

Best Python code snippet using locust

dist.py

Source:dist.py Github

copy

Full Screen

...46 parser.add_option('--pgp-key-id', metavar='KEYID',47 default='EFBADFBC',48 help='PGP signing key (default %default)')49 return parser.parse_args(args)50def remove_file_if_exists(fspath):51 try:52 os.unlink(fspath)53 except OSError, e:54 if e.errno != errno.ENOENT:55 raise56def main(args = None):57 if args is None:58 args = sys.argv[1:]59 (options, args) = parse_args(args)60 def log_level():61 if options.verbose:62 return logging.DEBUG63 return logging.INFO64 logging.basicConfig(stream = sys.stdout,65 format = '%(levelname) 7s: %(message)s',66 level = log_level())67 if options.mtn_db == '':68 logging.error('No monotone db set (use --mtn-db)')69 return 170 if not os.access(options.mtn_db, os.R_OK):71 logging.error('Monotone db %s not found' % (options.mtn_db))72 return 173 if len(args) != 1:74 logging.error('Usage: %s version' % (sys.argv[0]))75 return 176 try:77 version = args[0]78 rev_id = run_monotone(options.mtn_db,79 ['automate', 'select', 't:' + version])80 if rev_id == '':81 logging.error('No revision for %s found' % (version))82 return 283 output_basename = 'Botan-' + version84 output_name = os.path.join(options.output_dir, output_basename)85 output_tgz = output_name + '.tgz'86 output_tbz = output_name + '.tbz'87 logging.info('Found revision id %s' % (rev_id))88 if os.access(output_name, os.X_OK):89 shutil.rmtree(output_name)90 run_monotone(options.mtn_db,91 ['checkout', '-r', rev_id, output_name])92 shutil.rmtree(os.path.join(output_name, '_MTN'))93 remove_file_if_exists(os.path.join(output_name, '.mtn-ignore'))94 version_file = os.path.join(output_name, 'botan_version.py')95 if os.access(version_file, os.R_OK):96 # rewrite botan_version.py97 contents = open(version_file).readlines()98 def content_rewriter():99 for line in contents:100 if line == 'release_vc_rev = None\n':101 yield 'release_vc_rev = \'mtn:%s\'\n' % (rev_id)102 else:103 yield line104 open(version_file, 'w').write(''.join(list(content_rewriter())))105 os.chdir(options.output_dir)106 remove_file_if_exists(output_tgz)107 remove_file_if_exists(output_tgz + '.asc')108 archive = tarfile.open(output_tgz, 'w:gz')109 archive.add(output_basename)110 archive.close()111 if options.pgp_key_id != '':112 gpg_sign(output_tgz, options.pgp_key_id)113 remove_file_if_exists(output_tbz)114 remove_file_if_exists(output_tbz + '.asc')115 archive = tarfile.open(output_tbz, 'w:bz2')116 archive.add(output_basename)117 archive.close()118 if options.pgp_key_id != '':119 gpg_sign(output_tbz, options.pgp_key_id)120 shutil.rmtree(output_name)121 except Exception, e:122 import traceback123 traceback.print_exc(file=sys.stderr)124 logging.error(str(e))125 return 1126if __name__ == '__main__':...

Full Screen

Full Screen

serialization.py

Source:serialization.py Github

copy

Full Screen

...42 data = msgpack.load(file(filename, 'rb'), raw=False)43 result = HTTPResponse.from_dict(data)44 except:45 if remove:46 remove_file_if_exists(filename)47 raise48 else:49 if remove:50 remove_file_if_exists(filename)51 return result52def write_tags_to_temp_file(tag_list):53 """54 Write an Tag list to a temp file using msgpack55 :param tag_list: The Tag list56 :return: The name of the file57 """58 temp = get_temp_file('tags')59 data = [t.to_dict() for t in tag_list]60 msgpack.dump(data, temp, use_bin_type=True)61 temp.close()62 return temp.name63def load_tags_from_temp_file(filename, remove=True):64 """65 :param filename: The filename that holds the Tags as msgpack66 :param remove: Remove the file after reading67 :return: A list containing tags68 """69 try:70 data = msgpack.load(file(filename, 'rb'), raw=False)71 result = [Tag.from_dict(t) for t in data]72 except:73 if remove:74 remove_file_if_exists(filename)75 raise76 else:77 if remove:78 remove_file_if_exists(filename)79 return result80def get_temp_file(_type):81 """82 :return: A named temporary file which will not be removed on close83 """84 temp = tempfile.NamedTemporaryFile(prefix='w3af-%s-' % _type,85 suffix='.pebble',86 delete=False,87 dir=get_temp_dir())88 return temp89def write_object_to_temp_file(obj):90 """91 Write an object to a temp file using cPickle to serialize92 :param obj: The object93 :return: The name of the file94 """95 temp = get_temp_file('parser')96 cPickle.dump(obj, temp, cPickle.HIGHEST_PROTOCOL)97 temp.close()98 return temp.name99def load_object_from_temp_file(filename, remove=True):100 """101 Load an object from a temp file102 :param filename: The filename where the cPickle serialized object lives103 :param remove: Remove the file after reading104 :return: The object instance105 """106 try:107 result = cPickle.load(file(filename, 'rb'))108 except:109 if remove:110 remove_file_if_exists(filename)111 raise112 else:113 if remove:114 remove_file_if_exists(filename)115 return result116def remove_file_if_exists(filename):117 """118 Remove the file if it exists119 :param filename: The file to remove120 :return: None121 """122 try:123 os.remove(filename)124 except:...

Full Screen

Full Screen

_build.py

Source:_build.py Github

copy

Full Screen

...4from _version import __version__5def remove_dir_if_exists(path):6 if os.path.isdir(path):7 shutil.rmtree(path)8def remove_file_if_exists(path):9 if os.path.isfile(path):10 os.remove(path)11def build_zip():12 os.system('pyinstaller --onefile --paths venv main.py')13 with zipfile.ZipFile(f'tele2-profit@{__version__}.zip', 'w',14 zipfile.ZIP_DEFLATED) as zip_file:15 zip_file.write('dist/main.exe', 'main.exe')16if __name__ == '__main__':17 remove_file_if_exists(f'tele2-profit@{__version__}.zip')18 build_zip()19 remove_dir_if_exists('dist')20 remove_dir_if_exists('build')21 remove_dir_if_exists('__pycache__')...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful