-
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 21, 2020
1 parent
eab8660
commit e29741f
Showing
8 changed files
with
111 additions
and
26 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,19 @@ | ||
Copyright (c) 2018 The Python Packaging Authority | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,5 @@ | ||
# Example Package | ||
|
||
This is a simple example package. You can use | ||
[Github-flavored Markdown](https://guides.github.com/features/mastering-markdown/) | ||
to write your content. |
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 @@ | ||
from .egrep import egrep |
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
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,14 @@ | ||
class EgrepErrors(Exception): | ||
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: " | ||
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" |
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 |
---|---|---|
@@ -1,18 +1,22 @@ | ||
from setuptools import setup | ||
import setuptools | ||
|
||
with open("README.md", "r") as fh: | ||
long_description = fh.read() | ||
|
||
setup( | ||
setuptools.setup( | ||
name='egrep', | ||
version='0.0.1', | ||
version='0.0.3', | ||
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 | ||
url='https://github.com/rhimmelbauer/egrep', | ||
packages=setuptools.find_packages(), | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=python3.7', | ||
) |