def remove_lines_in_file(build, filename, containing): build.log.debug("removing lines containing '{containing}' in {filename}".format(**locals())) tmp_file = uuid.uuid4().hex in_file_contents = read_file_as_str(filename) in_file_contents = re.sub(r".*"+re.escape(containing)+r".*\r?\n?", "", in_file_contents) with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def _replace_in_file(build, filename, find, replace): build.log.debug(u"replacing {find} with {replace} in {filename}".format(**locals())) tmp_file = uuid.uuid4().hex in_file_contents = read_file_as_str(filename) in_file_contents = in_file_contents.replace(find, replace) with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def _replace_in_file(build, filename, find, replace): build.log.debug( u"replacing {find} with {replace} in {filename}".format(**locals())) tmp_file = uuid.uuid4().hex in_file_contents = read_file_as_str(filename) in_file_contents = in_file_contents.replace(find, replace) with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def regex_replace_in_file(build, filename, find, replace, template=False): build.log.debug("regex replace in {filename}".format(**locals())) if template: replace = utils.render_string(build.config, replace) tmp_file = uuid.uuid4().hex in_file_contents = read_file_as_str(filename) in_file_contents = re.sub(find, replace, in_file_contents) with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def remove_lines_in_file(build, filename, containing): build.log.debug( "removing lines containing '{containing}' in {filename}".format( **locals())) tmp_file = uuid.uuid4().hex in_file_contents = read_file_as_str(filename) in_file_contents = re.sub(r".*" + re.escape(containing) + r".*\r?\n?", "", in_file_contents) with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def wrap_activations(build, location): '''Wrap user activation code to prevent running in frames if required ''' if "activations" in build.config['modules'] and \ "config" in build.config['modules']['activations'] and \ "activations" in build.config['modules']['activations']['config']: for activation in build.config['modules']['activations']['config']['activations']: if not 'all_frames' in activation or activation['all_frames'] is False: for script in activation['scripts']: tmp_file = uuid.uuid4().hex filename = location+script[3:] build.log.debug("wrapping activation {filename}".format(**locals())) in_file_contents = read_file_as_str(filename) in_file_contents = 'if (forge._disableFrames === undefined || window.location == window.parent.location) {\n'+in_file_contents+'\n}'; with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)
def wrap_activations(build, location): '''Wrap user activation code to prevent running in frames if required ''' if "activations" in build.config['modules'] and \ "config" in build.config['modules']['activations'] and \ "activations" in build.config['modules']['activations']['config']: for activation in build.config['modules']['activations']['config'][ 'activations']: if not 'all_frames' in activation or activation[ 'all_frames'] is False: for script in activation['scripts']: tmp_file = uuid.uuid4().hex filename = location + script[3:] build.log.debug( "wrapping activation {filename}".format(**locals())) in_file_contents = read_file_as_str(filename) in_file_contents = 'if (forge._disableFrames === undefined || window.location == window.parent.location) {\n' + in_file_contents + '\n}' with codecs.open(tmp_file, 'w', encoding='utf8') as out_file: out_file.write(in_file_contents) os.remove(filename) shutil.move(tmp_file, filename)