@@ -14,129 +14,9 @@ def __init__(self,search):
1414 self .os = os .name
1515 self .foundList = []
1616 self .headerList = []
17- self .width = None
18- self .height = None
1917
20- 21- 22- #Calls to main Functions of program
23- 24- self .searchDB (search )
25- self .getTerminalSize ()
26- resultsPagesList = self .createPageLists (self .foundList )
27- self .createPageListing (resultsPagesList )
28- 29- def getTerminalSize (self ):
30- 31- env = os .environ
32- def ioctl_GWINSZ (fd ):
33- try :
34- import fcntl , termios , struct , os
35- cr = struct .unpack ('hh' , fcntl .ioctl (fd , termios .TIOCGWINSZ ,
36- '1234' ))
37- except :
38- return
39- return cr
40- cr = ioctl_GWINSZ (0 ) or ioctl_GWINSZ (1 ) or ioctl_GWINSZ (2 )
41- if not cr :
42- try :
43- fd = os .open (os .ctermid (), os .O_RDONLY )
44- cr = ioctl_GWINSZ (fd )
45- os .close (fd )
46- except :
47- pass
48- if not cr :
49- cr = (env .get ('LINES' , 25 ), env .get ('COLUMNS' , 80 ))
50- 51- ### Use get(key[, default]) instead of a try/catch
52- #try:
53- # cr = (env['LINES'], env['COLUMNS'])
54- #except:
55- # cr = (25, 80)
56- 57- self .width = int (cr [1 ])
58- self .height = int (cr [0 ])
59- 60- 61- 62- 63- def createTempFile (self ,path ): #Writes and opens a temporary file with the shell code in it.
64- with open (path ,mode = "r" ,encoding = "utf-8" ) as myFile :
65- content = myFile .readlines ()
66- 67- with tempfile .NamedTemporaryFile (mode = "w" ,delete = False ) as temp :
68- 69- for line in content :
70- temp .write (line )
71- 72- temp .flush ()
73- 74- if self .os == "nt" : #NT Systems - Windows
75- 76- os .system ('start notepad.exe ' + temp .name )
77- 78- else : #Linux Systems
79- os .system ('%s %s' % (os .getenv ('EDITOR' ), temp .name ))
80- 81- def createPageLists (self ,results ):
82- 83- #Too much data to output at once format into pages
84- resultsPagesList = []
85- 86- totalResults = len (results )
87- 88- if totalResults > 10 :
89- 90- totalPages = int (totalResults // 10 )
91- 92- if (totalResults % 10 ) > 0 :
93- 94- totalPages += 1
95- 96- 97- 98- for page in range (1 ,totalPages + 1 ):
99- 100- resultsList = []
101- 102- #Counter Variables for creating lists for each page
103- 104- endNum = (page * 10 )
105- 106- startNum = (page * 10 ) - 10
107- 108- #If last page use the total pages variable as the end number
109- 110- if endNum > totalResults :
111- 112- endNum = totalResults
113- 114- #Create lists
115- 116- resultsList = results [startNum :endNum ]
117- 118- resultsPagesList .append (resultsList )
119- 120- 121- #10 or less results = one page
122- 123- else :
124- 125- endNum = totalResults
126- 127- startNum = 0
128- 129- #Create lists
130- 131- resultsList = results [startNum :endNum ]
132- 133- resultsPagesList .append (resultsList )
134- 135- 136- return resultsPagesList
137- 138- def searchDB (self ,search ):
139- 18+ def searchDB (self ):
19+ search = self .search
14020 openFile = open (self .file , "r" )
14121
14222 reader = csv .reader (openFile )
0 commit comments