-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_file_back1.py
116 lines (73 loc) · 2.43 KB
/
test_file_back1.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python
import os
import sys
from diff_file_data import *
#display the options to select the required drivers
# /option_name[]: array containing name of the files
# /list_length: length of array option_name
def disp(list_length):
print 'Select the driver'
for num in range(0,list_length):
print '%s' % option_name[num]
#Reading input from the user
# /user_input: input by user
def inp(list_length):
user_input = int(input("Enter a choice: "))
if user_input >=1 and user_input<=list_length:
return user_input-1
else:
inp(list_length)
#depending on the user choice the elements from the list are selected
# /file_path[]: array of paths of the selected drivers
# /list_length: number of pair of files that can be compared
#function_to_display_the_choices
# /required_file: the required driver files which have to be compared
# /shell_command: return command for shell execution
# /diff_name: the name of the generated diff file
def select(user_input, list_length,temp):
diff_name=option_name[user_input]
file_path=fil[user_input]
for num in (0,len(file_path)):
files=file_path[num]
first_file=files[0]
second_file=files[1]
return_statement=command_line_statement(first_file,second_file,temp)
call(return_statement)
con_catenate(diff_name)
#function to get the string to be used as shell commmand
# /first_file: input file 1
# /second_file: input file 2
# /required_file: output diff file
# /returns: return value of diff
def command_line_statement(first_file,second_file,required_file):
return ('diff %s %s > %s.txt') % (first_file,second_file,required_file)
#to run the command in shell we use os.system
# /return_statement: return command for shell execution
def call(return_statement):
os.system(return_statement)
#concatanate multiple diff_files generated
# /file_name: name of the final diff file
def con_catenate(file_name):
statement=('cat temp.txt >> %s.txt') % file_name
os.system(statement)
#open the diff file or display the error element
def file_display(req_file):
shell_command= 'gvim %s.txt' %req_file
os.system(shell_command)
#set variables to zero
# /usip: user input to select the file
# /ret: return statement generated
# /req: required file name
# /ret: return value of diff
# /name: length of array option_name
# /path: length of array file_path
usip=0
ret=0
t='temp'
req=0
name=len(option_name)
path=len(fil)
disp(name)
usip=inp(name)
select(usip,path,t)
file_display(usip)