Ejemplo n.º 1
0
def file_get_contents(filename):
    with open(filename, 'rb') as f:
        return f.read()


def file_set_contents(filename, contents):
    with open(filename, 'wb') as f:
        f.write(contents)


#input = workflow.get_input()
#input = file_get_contents(editor.get_path())
input64 = editor.get_text()
input = base64.b64decode(input64)

root, documentfilename = editor.to_relative_path(editor.get_path())

# prompt user for password
password = console.password_alert("Document Password Required",
                                  "Enter your password", '', "OK")

inputfile = tempfile.NamedTemporaryFile(delete=False)
outputfile = tempfile.NamedTemporaryFile(delete=False)
file_set_contents(inputfile.name, input)
decryptFile(inputfile, password, outputfile)
result = file_get_contents(outputfile.name)
os.remove(inputfile.name)
os.remove(outputfile.name)
end = len(input64)
editor.replace_text(0, end, result)
console.hud_alert('Decryption Completed', 'info')
Ejemplo n.º 2
0
    elif exif[orientation] == 8:
        img = image.rotate(90, expand=True)
# cases: image don't have getexif
except (AttributeError, KeyError, IndexError):
    pass

doc_path = editor.get_path()
doc_dir, fn = os.path.split(doc_path)
default_name = '%s' % timestr + '_' + 'image'

i = 1
while True:
    if not os.path.exists(os.path.join(doc_dir, default_name + '.jpg')):
        break
    default_name = '%s' % timestr + '_' + 'image' + '_' + str(i)
    i += 1

root, rel_doc_path = editor.to_relative_path(editor.get_path())
filename = default_name + '.jpg'

if not filename:
    workflow.stop()

img_data = io.BytesIO()
img.save(img_data, 'jpeg')

rel_doc_dir, fn = os.path.split(rel_doc_path)
dest_path = os.path.join(rel_doc_dir, filename)
editor.set_file_contents(dest_path, img_data.getvalue(), root)
workflow.set_output(filename)
Ejemplo n.º 3
0
    fp.close()
    outfile.close()

def file_get_contents(filename):
    with open(filename,'rb') as f:
        return f.read()

def file_set_contents(filename, contents):
    with open(filename,'wb') as f:
        f.write(contents)
				
#input = workflow.get_input()
#input = file_get_contents(editor.get_path())
input = editor.get_text()

root, documentfilename = editor.to_relative_path(editor.get_path())

# prompt user for password
password = console.password_alert("Document Password Required", "Enter your password",'',"OK")

inputfile = tempfile.NamedTemporaryFile(delete=False)
outputfile = tempfile.NamedTemporaryFile(delete=False)
file_set_contents(inputfile.name, input)
encryptFile(inputfile, password, outputfile)
result = file_get_contents(outputfile.name)
os.remove(inputfile.name)
os.remove(outputfile.name)
end = len(input)
result64 = base64.b64encode(result)
editor.replace_text(0,end,result64)
console.hud_alert('Encryption Completed', 'info')
Ejemplo n.º 4
0
            continue

        x = 0

        try:
            for n in range(len(term_array)):
                if re.search(term_array[n].lower(), name.lower()):
                    x += 1
        except UnicodeDecodeError, e:
            pass

        if x == len(term_array):
            match_count += 1
            filename_match += 1
            match_check += 1
            root, rel_path = editor.to_relative_path(full_path)
            ed_url = 'editorial://open/' + quote(
                rel_path.encode('utf-8')) + '?root=' + root
            html.write('<h2><a href="' + ed_url + '">' + name + '</a></h2>')

        found_snippets = []
        i = 0
        try:
            with codecs.open(full_path, 'r', 'utf-8') as f:
                if term in f.read():
                    for line in f:
                        for match in re.finditer(pattern, line):
                            start = max(0, match.start(0) - 100)
                            end = min(len(line) - 1, match.end(0) + 100)
                            snippet = (line[start:match.start(0)],
                                       match.group(0), line[match.end(0):end],
Ejemplo n.º 5
0
					continue

			x = 0

			try:
					for n in range(len(term_array)):
							if re.search(term_array[n].lower(), name.lower()):
									x += 1
			except UnicodeDecodeError, e:
					pass

			if x == len(term_array):
					match_count += 1
					filename_match += 1
					match_check += 1
					root, rel_path = editor.to_relative_path(full_path)
					ed_url = 'editorial://open/' + quote(rel_path.encode('utf-8')) + '?root=' + root
					html.write('<h2><a href="' + ed_url + '">' + name + '</a></h2>')

			found_snippets = []
			i = 0
			try:
					with codecs.open(full_path, 'r', 'utf-8') as f:
						if term in f.read():
							for line in f:
								for match in re.finditer(pattern, line):
									start = max(0, match.start(0) - 100)
									end = min(len(line)-1, match.end(0) + 100)
									snippet = (line[start:match.start(0)],
															match.group(0),
															line[match.end(0):end],
Ejemplo n.º 6
0
	if rot_degrees:
		img = img.rotate(rot_degrees, expand=True)
# cases: image don't have getexif
except (AttributeError, KeyError, IndexError):
	pass

doc_path = editor.get_path()
doc_dir, fn = os.path.split(doc_path)
default_name = '{}_image'.format(timestr)

i = 1
while True:
	if not os.path.exists(os.path.join(doc_dir, default_name + '.jpg')):
		break
	default_name = '{}_image_{}'.format(timestr, i)
	i += 1

root, rel_doc_path = editor.to_relative_path(editor.get_path())
filename = default_name + '.jpg'

if not filename:
	workflow.stop()

img_data = io.BytesIO()
img.save(img_data, 'jpeg')

rel_doc_dir, fn = os.path.split(rel_doc_path)
dest_path = os.path.join(rel_doc_dir, filename)
editor.set_file_contents(dest_path, img_data.getvalue(), root)
workflow.set_output(filename)