null+****@clear*****
null+****@clear*****
2012年 5月 8日 (火) 18:18:08 JST
Kouhei Sutou 2012-05-08 18:18:08 +0900 (Tue, 08 May 2012)
New Revision: d1fbe7c4ad399208fea7588c8b8ff14c686b50f2
Log:
doc: make execution examples copy & paste friendly
* remove "> " prompt from command lines
* prepend "# " to result lines
Lines that start with "# " are ignored by groonga because they are
treated as comment lines.
Modified files:
doc/update_execution_example.py
Modified: doc/update_execution_example.py (+10 -7)
===================================================================
--- doc/update_execution_example.py 2012-05-08 17:49:20 +0900 (15bc0fb)
+++ doc/update_execution_example.py 2012-05-08 18:18:08 +0900 (bcc3993)
@@ -38,15 +38,16 @@ def reconnect(name):
fout = None
def execmd(command, fout):
- formatted_command_line = '> ' + command + "\n"
- stdout.write(formatted_command_line)
+ formatted_command_line = " " + command + "\n"
+ stdout.write(command + "\n")
stdout.flush()
groonga_process.stdin.write(command + "\n")
groonga_process.stdin.flush()
if fout:
- fout.write(formatted_command_line + " ")
+ fout.write(formatted_command_line)
is_command = re.match("[a-z]", command)
- if not is_command:
+ is_load_data_end = re.match("^\]", command)
+ if not is_command and not is_load_data_end:
return
output_buffer = ""
while True:
@@ -71,7 +72,9 @@ def execmd(command, fout):
formatted_output = formatted_output.encode("utf-8")
stdout.write(formatted_output)
if fout:
- fout.write(re.sub("\n", "\n ", formatted_output))
+ first_lines_re = re.compile("^", re.M)
+ fout.write(first_lines_re.sub(" # ", formatted_output.strip()))
+ fout.write("\n")
output_buffer = ""
else:
stdout.flush()
@@ -116,7 +119,7 @@ def readfile(fname, outflag):
os.makedirs(dir_name)
fout = open(a, 'w')
print '### write start : ' + a
- fout.write("Execution example::\n\n ")
+ fout.write("Execution example::\n\n")
elif cmd.startswith('.. % '):
a = cmd[5:]
if fout:
@@ -129,7 +132,7 @@ def readfile(fname, outflag):
fout.write(a + "\n ")
print a
elif cmd.startswith('..'):
- if cmd.replace(' ','').replace("\t",'') == '..':
+ if cmd.replace(' ', '').replace("\t", '') == '..':
while len(dat):
if dat[0] == '' or (dat[0][0] != ' ' and dat[0][0] != ' '):
break