Skip to content

Commit

Permalink
Code refactoring, moved modules on top level 💥 ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
amitt001 committed Jul 2, 2018
1 parent 2be4b63 commit 6032547
Show file tree
Hide file tree
Showing 109 changed files with 41 additions and 49 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ bootstrap.min.css
# Directory
*.egg-info/
env
env3
.idea
.vscode
dist
.DS_Store
.cache
.pytest_cache/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install:
- pip install coveralls

script:
- coverage run --source src/pygmy -m py.test
- coverage run --source pygmy -m py.test

after_success:
- coveralls
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p align="center"><img src="src/pyui/static/logo/logov2.png" alt="pygmy" height="200px"></p>
<p align="center"><img src="qolugo/static/logo/logov2.png" alt="pygmy" height="200px"></p>

Pygmy
=====
Expand Down Expand Up @@ -55,7 +55,7 @@ Technical Info

- Python 3, Javascript, JQuery, HTML, CSS
- REST API: Flask
- Pyui: Django(It serves the web user interface)
- Qolugo: Django(It serves the web user interface)
- DB: PostgreSQL/MySQL/SQLite
- Others: SQLAlchmey, JWT

Expand All @@ -77,12 +77,12 @@ NOTE: **This module only supports Python 3. Make sure pip and virtualenv are bot
Note:

1. The project has two config files:
- pygmy.cfg: `src/pygmy/config/pygmy.cfg` rest API and pygmy core settings file
- settings.py: `src/pyui/pyui/settings.py` Django settings file
- pygmy.cfg: `pygmy/config/pygmy.cfg` rest API and pygmy core settings file
- settings.py: `qolugo/qolugo/settings.py` Django settings file
2. SQLite is default db, if you are using PostgreSQL or MySQL with this project, make sure they are installed into the system.
3. To modify config settings vim `src/pygmy/config/pygmy.cfg`
3. To modify config settings vim `pygmy/config/pygmy.cfg`
4. You can run pygmy shell present in src directory to run the program on terminal. `python shell`
5. By default in `src/pyui/pyui/settings.py` DEBUG is set to True, set it to False in production
5. By default in `qolugo/qolugo/settings.py` DEBUG is set to True, set it to False in production

DB Setup:
=========
Expand All @@ -98,7 +98,7 @@ Check correct port:

`mysqladmin variables | grep port`

Change below line in `src/pygmy/core/pygmy.cfg`:
Change below line in `pygmy/core/pygmy.cfg`:

```
engine: mysql
Expand Down Expand Up @@ -150,7 +150,7 @@ Get Link:
Shell Usage
===========

Open shell using ./pygmy/src/shell. Available context is pygmy, Config, DB, etc. See all context by using pygmy_context.
Open shell using ./shell. Available context is pygmy, Config, DB, etc. See all context by using pygmy_context.

Shorten a link:

Expand Down Expand Up @@ -225,7 +225,7 @@ Docstring:
How Link Stats Are Generated?
=============================

For getting geo location stats from IP maxminds' [GeoLite2-Country.mmd](http://pygy.co/cm) database is used. It's in `src/pygmy/app` directory.
For getting geo location stats from IP maxminds' [GeoLite2-Country.mmd](http://pygy.co/cm) database is used. It's in `pygmy/app` directory.

How Pygmy Auth Token Works?
===========================
Expand All @@ -237,7 +237,7 @@ Development

Run tests and generate a coverage report:

`coverage run --source src/pygmy -m py.test`
`coverage run --source pygmy -m py.test`

See coverage report:

Expand Down
8 changes: 4 additions & 4 deletions init.d/pyui
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash
# init.d script for pyui app
# init.d script for qolugo app

NAME=pyui
NAME=qolugo
PIDFILE=/var/run/$NAME.pid

PORT=8000
APP_DIR=/opt/pygyco/src/pyui
APP_DIR=/opt/pygyco/qolugo
PYTHONPATH='/opt/pygyco/env/bin/gunicorn'
APP_ARGS='--log-file /var/log/pygmy/uierror_logs.log --access-logfile /var/log/pygmy/uiacclogs.log --bind 127.0.0.1:8000 --workers 2 pyui.wsgi'
APP_ARGS='--log-file /var/log/pygmy/uierror_logs.log --access-logfile /var/log/pygmy/uiacclogs.log --bind 127.0.0.1:8000 --workers 2 qolugo.wsgi'
APP_STOP_ARGS='--stop $PIDFILE'
APP_RELOAD_ARGS='--reload $PIDFILE'

Expand Down
1 change: 1 addition & 0 deletions pygmy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name = 'pygmy'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/pygmy/config/config.py → pygmy/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def initialize(self):
self.schema = self.cfg['pygmy']['schema']
self.host = self.cfg['pygmy']['host']
self.port = self.cfg['pygmy']['port']
self.secret = self.cfg['rest']['flask_secret']
self.secret = self.cfg['pygmy']['flask_secret']
self.webservice_url = "{0}://{1}:{2}".format(
self.schema, self.host, self.port)

if self.database['engine'] == 'sqlite3':
root_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sqlite_path = root_dir + '/' + self.database['data_dir'] + '/' + self.database['file_name']
self.database['url'] = 'sqlite:///{}'.format(sqlite_path)

9 changes: 1 addition & 8 deletions src/pygmy/config/pygmy.cfg → pygmy/config/pygmy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ short_url_schema = http://
[database]
file_name: pygmy.db
engine: sqlite3
url: sqlite:////var/lib/pygmy/pygmy.db
data_dir = data
# postgres://[email protected]:5432/pygmy
# sqlite:////var/lib/pygmy/pygmy.db
# url: postgres://[email protected]:5432/pygmy
# mysql+pymysql://root:[email protected]:3306/pygmy
user:
password:
host:
port:

[rest]
host = 127.0.0.1
port = 9119
flask_secret = CvJHGFVBj*&^TRGBHDdBV836bdy73JJDHGV

[auth]
refresh_secret = _))_((*REFRESH)(*_)+_
access_secret = +_)R@nd0m(_+
Expand Down
10 changes: 2 additions & 8 deletions src/pygmy/config/pygmy_test.cfg → pygmy/config/pygmy_test.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
schema = http
host = 0.0.0.0
port = 9119
debug = False
debug = True
flask_secret = CvJHGFVBj*&^TRGBHDdBV836bdy73JJDHGV
short_url = 127.0.0.1
short_url_schema = http://

[database]
file_name: pygmy_test.db
engine: sqlite3
url: sqlite:////var/lib/pygmy/pygmy_test.db
data_dir = data
# postgres://[email protected]:5432/pygmy
# url: postgres://[email protected]:5432/pygmy
# sqlite:////var/lib/pygmy/pygmy.db
# mysql+pymysql://root:[email protected]:3306/pygmy
user:
password:
host:
port:

[rest]
host = 127.0.0.1
port = 9119
flask_secret = CvJHGFVBj*&^TRGBHDdBV836bdy73JJDHGV

[auth]
refresh_secret = _))_((*REFRESH)(*_)+_
access_secret = +_)R@nd0m(_+
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pygmy/core/initialize.py → pygmy/core/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pygmy.database.factory import DatabaseFactory

_CONFIG_ENV_VAR = 'PYGMY_CONFIG_FILE'
_CFG_PATHS = ['src/pygmy/config/pygmy.cfg', 'pygmy/config/pygmy.cfg', 'pygmy.cfg',
_CFG_PATHS = ['pygmy/config/pygmy.cfg', 'pygmy.cfg',
'$HOME/.pygmy.cfg', '/etc/pygmy.cfg'
'tests/pygmy_test.cfg', 'pygmy/config/pygmy_test.cfg']

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions pygmy/validator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .link import LinkSchema
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/pygmy_api_run.py → pygmy_api_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@


if __name__ == '__main__':

# TODO: Use argparsep
if len(sys.argv) > 1 and sys.argv[1] == 'test':
print('Running Pygmy API test server')

config_path = 'pygmy/config/pygmy_test.cfg'
db_file_path = tempfile.NamedTemporaryFile(suffix='.db').name
db_path = "sqlite:///{}".format(db_file_path)

initialize_test(config_path, db_url=db_path)
else:
print('Running Pygmy API server')
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/pyui/manage.py → qolugo/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyui.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qolugo.settings")
try:
from django.core.management import execute_from_command_line

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/pyui/pyui/settings.py → qolugo/qolugo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
'middleware.exception.ExceptionMiddleware'
]

ROOT_URLCONF = 'pyui.urls'
ROOT_URLCONF = 'qolugo.urls'

TEMPLATES = [
{
Expand All @@ -79,7 +79,7 @@
PROJECT_DIR = os.path.dirname(__file__)


WSGI_APPLICATION = 'pyui.wsgi.application'
WSGI_APPLICATION = 'qolugo.wsgi.application'


# Database
Expand Down
4 changes: 2 additions & 2 deletions src/pyui/pyui/urls.py → qolugo/qolugo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
from django.conf import settings
from django.conf.urls import url, include
import pyui.generic_views as views
import qolugo.generic_views as views


urlpatterns = [
Expand All @@ -28,4 +28,4 @@

if settings.DEBUG is True:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns += staticfiles_urlpatterns()
urlpatterns += staticfiles_urlpatterns()
2 changes: 1 addition & 1 deletion src/pyui/pyui/wsgi.py → qolugo/qolugo/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pyui.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qolugo.settings")

application = get_wsgi_application()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<link rel="stylesheet" href="/static/css/styles.css">

<!--Favicon-->
<link rel="shortcut icon" type="image/png" href="/static/logo/logov2.ico"/>
<link rel="shortcut icon" type="image/png" href="/static/logo/logov2.png"/>

<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
<script src="/static/js/app.js"></script>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/run.py → run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


PYGMY_API_ARGS = ['gunicorn', '-b 127.0.0.1:9119', '-w 1', 'pygmy.rest.wsgi:app']
PYUI_ARGS = ['gunicorn', '-b 127.0.0.1:8000', '-w 1', 'pyui.wsgi']
QOLUGO_ARGS = ['gunicorn', '-b 127.0.0.1:8000', '-w 1', 'qolugo.wsgi']
process = []


Expand All @@ -25,8 +25,8 @@ def print_err(proc, timeout=2):
# Print any configuration error
print_err(process[-1])
print("Starting development server at http://127.0.0.1:8000/")
os.chdir('src/pyui')
process.append(subprocess.Popen(PYUI_ARGS, stdout=subprocess.PIPE,
os.chdir('qolugo')
process.append(subprocess.Popen(QOLUGO_ARGS, stdout=subprocess.PIPE,
stderr=subprocess.PIPE))
# Print any configuration error
print_err(process[-1])
Expand Down
File renamed without changes.
1 change: 0 additions & 1 deletion src/pygmy/validator/__init__.py

This file was deleted.

Empty file removed src/tests/__init__.py
Empty file.
Empty file removed test.py
Empty file.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions src/tests/fixture.py → tests/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PygmyApiTestServer:
@classmethod
def start_pygmy_api_server(cls):
# os.chdir('src')
command = ['coverage', 'run', 'src/pygmy_api_run.py', 'test']
command = ['coverage', 'run', 'pygmy_api_run.py', 'test']
cls.pygmyapi_proc = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for server to start
Expand All @@ -36,8 +36,7 @@ class PygmyUiTestServer:

@classmethod
def start_pygmy_ui_server(cls):
# os.chdir('src/pyui')
command = ['gunicorn','-b 127.0.0.1:8000', '--chdir', 'src/pyui', '-w 1', 'pyui.wsgi']
command = ['gunicorn','-b 127.0.0.1:8001', '--chdir', 'qolugo', '-w 1', 'qolugo.wsgi']
cls.pygmyui_proc = subprocess.Popen(
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Wait for server to start
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class PygmyIntegrationTest(unittest.TestCase):

@classmethod
def setup_class(cls):
cls.url = 'http://127.0.0.1:8000'
cls.url = 'http://127.0.0.1:8001'

@classmethod
def teardown_class(cls):
Expand Down

0 comments on commit 6032547

Please sign in to comment.