You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
763 B
26 lines
763 B
1 year ago
|
import os
|
||
|
import re
|
||
|
import console
|
||
|
|
||
|
def get_app_class(template):
|
||
|
class App(template):
|
||
|
def F_main(self):
|
||
|
pattern = self.argv[1].encode("utf-8")
|
||
|
file = self.argv[2]
|
||
|
|
||
|
try:
|
||
|
with open(file, "rb") as f:
|
||
|
for line in f.readlines():
|
||
|
if re.search(pattern, line):
|
||
|
self.console.write(line)
|
||
|
except OSError as e:
|
||
|
try:
|
||
|
os.listdir(file)
|
||
|
console.write_str(self.console, f"grep: {file}: Is a directory\n")
|
||
|
except OSError:
|
||
|
console.write_str(self.console, f"grep: {file}: No such file or directory\n")
|
||
|
|
||
|
self.exit()
|
||
|
|
||
|
return App
|