Compare commits
2 Commits
4b25f8f2bd
...
63c5ad520d
Author | SHA1 | Date | |
---|---|---|---|
63c5ad520d | |||
9757d2c18d |
25
bin/grep.py
Normal file
25
bin/grep.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
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
|
|
@ -1,3 +1,5 @@
|
||||||
|
from fibonaccios.exceptions import *
|
||||||
|
|
||||||
_cache = {}
|
_cache = {}
|
||||||
|
|
||||||
def get_app(app):
|
def get_app(app):
|
||||||
|
@ -6,7 +8,7 @@ def get_app(app):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
module = __import__(f'/bin/{app}')
|
module = __import__(f'/bin/{app}')
|
||||||
except AttributeError:
|
except ImportError:
|
||||||
raise AppNotFound(app)
|
raise AppNotFound(app)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user