Last active
August 29, 2015 14:01
-
-
Save gildotdev/e6d9bda6ae2dab1d67ca to your computer and use it in GitHub Desktop.
UltraEdit/Python script file for create CfMC repeat blocks out of a list file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'gilcreque' | |
MAX_LINE_LEN = 300 | |
UltraEdit.activeDocument.dosToUnix | |
UltraEdit.activeDocument.selectAll() | |
text_file = UltraEdit.activeDocument.selection | |
text_array = text_file.split("\n") | |
file_len = text_array.length | |
current_line_len = 0 | |
current_line = '' | |
for line in text_array | |
if _i < file_len | |
line = line.replace /^\s+|\s+$/g, "" + ', ' | |
else | |
line = line.replace /^\s+|\s+$/g, "" | |
if current_line_len + line.length < MAX_LINE_LEN | |
current_line += line | |
current_line_len += line.length | |
else | |
current_line += '&\n' + line | |
current_line_len = line.length | |
UltraEdit.outputWindow.showOutput = true | |
UltraEdit.outputWindow.write(current_line) | |
UltraEdit.newFile() | |
UltraEdit.activeDocument.write(current_line) | |
UltraEdit.activeDocument.unixMacToDos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by CoffeeScript 1.7.1 | |
(function() { | |
var MAX_LINE_LEN, current_line, current_line_len, file_len, line, text_array, text_file, __author__, _i, _len; | |
__author__ = 'gilcreque'; | |
MAX_LINE_LEN = 300; | |
UltraEdit.activeDocument.dosToUnix; | |
UltraEdit.activeDocument.selectAll(); | |
text_file = UltraEdit.activeDocument.selection; | |
text_array = text_file.split("\n"); | |
file_len = text_array.length; | |
current_line_len = 0; | |
current_line = ''; | |
for (_i = 0, _len = text_array.length; _i < _len; _i++) { | |
line = text_array[_i]; | |
if (_i < file_len) { | |
line = line.replace(/^\s+|\s+$/g, "" + ', '); | |
} else { | |
line = line.replace(/^\s+|\s+$/g, ""); | |
} | |
if (current_line_len + line.length < MAX_LINE_LEN) { | |
current_line += line; | |
current_line_len += line.length; | |
} else { | |
current_line += '&\n' + line; | |
current_line_len = line.length; | |
} | |
} | |
UltraEdit.outputWindow.showOutput = true; | |
UltraEdit.outputWindow.write(current_line); | |
UltraEdit.newFile(); | |
UltraEdit.activeDocument.write(current_line); | |
UltraEdit.activeDocument.unixMacToDos; | |
}).call(this); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import re | |
__author__ = 'gilcreque' | |
MAX_LINE_LEN = 300 | |
#check to see that minimum arguments were given | |
if len(sys.argv) == 1: | |
sys.stderr.write("Usage: " + sys.argv[0] + " Filename\n") | |
exit(2) | |
filename = sys.argv[1] | |
#check if text file exists and can be opened | |
try: | |
text_file = open(filename, 'r').readlines() | |
file_len = text_file.__len__() | |
except (IOError, NameError): | |
sys.stderr.write("filename: " + filename + " not found\n") | |
exit(2) | |
baseName = re.sub('\.[^.]*$', '', filename) | |
resultFileName = baseName + "_rep.txt" | |
try: | |
# This will create a new file or **overwrite an existing file**. | |
new_file = open(resultFileName, "wr+") | |
new_file.truncate() | |
current_line_len = 0 | |
i = 1 | |
try: | |
for line in text_file: | |
if i < file_len: | |
line = line.strip() + ', ' | |
else: | |
line = line.strip() | |
if current_line_len + line.__len__() < MAX_LINE_LEN: | |
new_file.write(line) | |
current_line_len += line.__len__() | |
else: | |
new_file.write(' &\n' + line) | |
current_line_len = line.__len__() | |
i += 1 | |
finally: | |
new_file.close() | |
except IOError, e: | |
sys.stderr.write("could not create/overwrite: " + resultFileName + '\n') | |
sys.stderr.write(str(e) + '\n') | |
exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment