Skip to content

Commit

Permalink
added egrep to __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Roberto Himmelbauer P authored and Roberto Himmelbauer P committed Apr 21, 2020
1 parent eab8660 commit e29741f
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 26 deletions.
19 changes: 19 additions & 0 deletions LICENSE
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.
5 changes: 5 additions & 0 deletions README.md
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 added build/lib/egrep/__init__.py
Empty file.
58 changes: 58 additions & 0 deletions build/lib/egrep/egrep.py
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)

1 change: 1 addition & 0 deletions egrep/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .egrep import egrep
22 changes: 3 additions & 19 deletions egrep/egrep.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
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"
from .EgrepErrors import EgrepErrors

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
Expand Down Expand Up @@ -50,9 +34,9 @@ def validateArguments(self, *args):

def isValidLength(self, *args):
if len(args) < self.MINIMUM_ARGUMENTS:
raise EgrepErrors(self.ERROR_INVALID_NUMBER_OF_ARGUMENTS)
raise EgrepErrors(EgrepErrors.ERROR_INVALID_NUMBER_OF_ARGUMENTS)

def isValidFilePath(self, filePath):
if path.exists(filePath) == False:
raise EgrepErrors(self.ERROR_FILE_DOES_NOT_EXIST_AT + filePath)
raise EgrepErrors(EgrepErrors.ERROR_FILE_DOES_NOT_EXIST_AT + filePath)

14 changes: 14 additions & 0 deletions egrep/egrepErrors.py
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"
18 changes: 11 additions & 7 deletions setup.py
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',
)

0 comments on commit e29741f

Please sign in to comment.