-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Roberto Himmelbauer P
authored and
Roberto Himmelbauer P
committed
Apr 17, 2020
0 parents
commit eab8660
Showing
7 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Compiled python modules. | ||
*.pyc | ||
|
||
# Setuptools distribution folder. | ||
/dist/ | ||
|
||
# Python egg metadata, regenerated from source files by setuptools. | ||
/*.egg-info |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import subprocess | ||
from os import path | ||
|
||
|
||
class EgrepErrors(Exception): | ||
def __init__(self, *args): | ||
if args: | ||
self.message = args[0] | ||
else: | ||
self.message = None | ||
|
||
def __str__(self): | ||
if self.message: | ||
return f"EGREP Exception Raised: {self.message}" | ||
else: | ||
return "EGREP Exception Raised" | ||
|
||
class egrep: | ||
ERROR_INVALID_NUMBER_OF_ARGUMENTS = "Invalid number of arguments. Need at least two, eg:\nEGREP(\"regex\",\"file-path\")" | ||
ERROR_FILE_DOES_NOT_EXIST_AT = "File does not exist at: " | ||
|
||
EGREP = "egrep " | ||
|
||
MINIMUM_ARGUMENTS = 2 | ||
|
||
def __init__(self, *args): | ||
try: | ||
if(self.validateArguments(*args)): | ||
self.command = self.EGREP + " ".join(args) | ||
|
||
except EgrepErrors as error: | ||
print(error) | ||
|
||
def execute(self): | ||
command = subprocess.Popen([self.command], stdout=subprocess.PIPE,shell=True) | ||
(command_output, error) = command.communicate() | ||
if error: | ||
raise EgrepErrors(error) | ||
else: | ||
for word in self.createOutputList(command_output): | ||
print(word) | ||
|
||
def createOutputList(self, command_output): | ||
return str(command_output)[1:].split("\\n") | ||
|
||
def validateArguments(self, *args): | ||
self.isValidLength(*args) | ||
self.isValidFilePath(args[-1]) | ||
return True | ||
|
||
def isValidLength(self, *args): | ||
if len(args) < self.MINIMUM_ARGUMENTS: | ||
raise EgrepErrors(self.ERROR_INVALID_NUMBER_OF_ARGUMENTS) | ||
|
||
def isValidFilePath(self, filePath): | ||
if path.exists(filePath) == False: | ||
raise EgrepErrors(self.ERROR_FILE_DOES_NOT_EXIST_AT + filePath) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from setuptools import setup | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
name='egrep', | ||
version='0.0.1', | ||
author='Roberto Himmelbauer', | ||
author_email='robertoh89@gmail.com', | ||
description='A simple library for exectuing egrep linux commando to files', | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url='https://github.com/sean-mcclure/datapeek_py', | ||
license='MIT', | ||
packages=['egrep'], | ||
zip_safe=False | ||
) |
Empty file.