Permalink
Browse files

Merge pull request #10 from LRParser/install_modified

Adding support for using local storage instead of S3, per config
  • Loading branch information...
mjbommar committed Aug 3, 2018
2 parents de917db + 4797199 commit 240729b22dc08227c3ba987339c1ef62c26cf4d6
@@ -57,7 +57,7 @@ an AWS account is required for S3 usage and performance will be substantially re

c. `$ ./env/bin/pip install -r lexpredict_openedgar/requirements/full.txt`

12. Setup database
12. Setup database. Note that the password chosen for openegar must be set as DJANGO_PASSWORD in the .env later

a. `$ sudo -u postgres createuser -l -P -s openedgar`

@@ -101,7 +101,7 @@ an AWS account is required for S3 usage and performance will be substantially re
$ sudo systemctl status rabbitmq-server.service
```

14. Update .env file
14. Update .env file. For local testing (downloading files locally, instead of to S3), set CLIENT_TYPE to LOCAL and DOWNLOAD_PATH to a local path

a. `$ cp lexpredict_openedgar/sample.env lexpredict_openedgar/.env`

@@ -0,0 +1,58 @@
"""
MIT License
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.
"""

# Libraries
import logging
import os

# Setup logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logger.addHandler(console)


class LocalClient:

def __init__(self):
logger.info("Initialized local client")

def path_exists(self, path: str):
return os.path.exists(path)

def put_buffer(self, file_path: str, buffer, write_bytes=True):
dir_name = os.path.dirname(file_path)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
if write_bytes:
mode="wb"
else:
mode="w"
with open(file_path, mode=mode) as localfile:
localfile.write(buffer)

def get_buffer(self, file_path: str):
with open(file_path, mode='rb') as localfile:
return localfile.read()
Oops, something went wrong.

0 comments on commit 240729b

Please sign in to comment.