-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_sfm_menu.py
96 lines (76 loc) · 2.63 KB
/
process_sfm_menu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#title : menu.py
#description : This program displays an interactive menu on CLI
#author :
#date :
#version : 0.1
#usage : python menu.py
#notes :
#python_version : 3.6
#=======================================================================
#Functions to be accessed via these menus are :
# 0) Read in an sfm file or CSV file and convert it to a list of lists.
# 1) Replace one marker with another, or with some other marker.
# 2) In a given field find the whole field and replace the data with some other data.
# 3) Save the modified SFM file.
# 4) Write to another file summary information about the input file.
# 5) Split the entries into two files depending on whether they are simple to import or not.
# 6) Write the simple entries out to a file with their fields consistently ordered.
# Import the modules needed to run the script.
import sys, os
# =======================
# MENUS FUNCTIONS
# =======================
#Show a pre-defined menu
def show_menu(rubric,lines,quit):
# os.system('cls' if os.name == 'nt' else 'clear')
valid_choices = [str(x) for x in range(1,len(lines)+1)]
#print("Valid choices are {}.\n".format(valid_choices))
for line in rubric :
print(line)
for i,line in enumerate(lines):
print(i+1, ') ' + line)
print("Valid choices are :")
for ch in valid_choices:
print("{}".format(ch),end=' ')
print("or {} to {}".format(quit[0],quit[1]))
choice = input(" >> ")
print("\n" * 2)
if choice == str(quit[0]):
exit()
while choice not in valid_choices:
choice = show_menu(rubric,lines,quit)
return choice
# Define a menu with a rubric, list of options and option to quit.
def main_menu():
rubric = [
"To process sfm or csv data.\n",\
"Please choose what you would like to do."\
]
lines = [
"Show information about the file.",\
"Change a marker.",\
"Duplicate a marker with a new name.",\
"Change data in a given field.",\
"Save the changes to an SFM file.",\
"Write summary information about the file.",\
"Write information about the sfm file to a file.",\
"Save the changes to an SFM file omitting most empty markers.",\
"List the unique data in a given marker.",\
"Split the file into simple-to-import and otherwise.",\
"Split marker according to script.",\
"Sort the sfm file.",\
"Print the sfm file to screen.",\
"Read in a typ file.",\
"Examine the Cross References in an SFM file.\n"]
quit = [0, "Quit\n"]
return (rubric,lines,quit)
# =======================
# MAIN PROGRAM
# =======================
# Main Program
if __name__ == "__main__":
# Launch main menu
main_menu = main_menu()
choice = show_menu(*main_menu)