예제 #1
0
def wrap_activations(build, location):
    """Wrap user activation code to prevent running in frames if required

	"""
    if (
        "activations" in build.config["plugins"]
        and "config" in build.config["plugins"]["activations"]
        and "activations" in build.config["plugins"]["activations"]["config"]
    ):
        for activation in build.config["plugins"]["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 = (
                        "// firefox complains when the first line is an if statement\n"
                        + "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)
예제 #2
0
 def _replace_in_file(filename, find, replace):
     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)
예제 #3
0
파일: ios_tasks.py 프로젝트: inokon/JoyList
		def _replace_in_file(filename, find, replace):
			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)
예제 #4
0
def regex_replace_in_file(build, filename, find, replace):
	build.log.debug("regex replace in {filename}".format(**locals()))
	
	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)
예제 #5
0
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("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)
예제 #7
0
def _replace_in_file(build, filename, find, replace):
    build.log.debug(
        "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)
예제 #8
0
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)
예제 #9
0
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 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)
예제 #11
0
def wrap_activations(build, location):
	'''Wrap user activation code to prevent running in frames if required
	
	'''
	for activation in build.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)
				os.rename(tmp_file, filename)
예제 #12
0
def wrap_activations(build, location):
    '''Wrap user activation code to prevent running in frames if required
	
	'''
    if "activations" in build.config['modules']:
        for activation in build.config['modules']['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)