Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1719 - Removes unused issues.db from the code #1720

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 16 additions & 54 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@

import argparse
import pkg_resources
from pkg_resources import DistributionNotFound, VersionConflict
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
import time
import os
from pkg_resources import DistributionNotFound
from pkg_resources import VersionConflict
import sys

IMPORT_ERROR = '''
Expand All @@ -35,7 +31,7 @@

try:
from webcompat import app
except ImportError, e:
except ImportError as e:
if 'import_name' in e and e.import_name == 'config':
# config not found, did you forget to copy config.py.example?
raise ImportError('{0}\n\n{1}'.format(e, NO_CONF_ERROR))
Expand Down Expand Up @@ -102,54 +98,20 @@ def config_validator():
parser = argparse.ArgumentParser()
parser.add_argument('-t', '--testmode', action='store_true',
help='Run server in "test mode".')
parser.add_argument('--backup', action='store_true',
help='backup existing issues.db.')
args = parser.parse_args()

if not args.testmode:
# testing the config file.
# this file is only important in non-test mode.
# in test mode everything must be mocked,
# so there is no external api communication.
config_validator()

if args.testmode:
# disable HttpOnly setting for session cookies so Selenium
# can interact with them. *ONLY* do this for testing.
app.config['SESSION_COOKIE_HTTPONLY'] = False
app.config['TESTING'] = True
print("Starting server in ~*TEST MODE*~")
app.run(host='localhost')
elif args.backup:
# Check 'BACKUP_DEFAULT_DEST' before backup
if 'BACKUP_DEFAULT_DEST' not in app.config.keys():
sys.exit('Please define BAKCUP_DEFAULT_DEST in secrets.py.')

issue_engine = create_engine(
'sqlite:///' + os.path.join(app.config['BASE_DIR'], 'issues.db'))
issue_session_maker = sessionmaker(autocommit=False,
autoflush=False,
bind=issue_engine)
issue_db = scoped_session(issue_session_maker)
# Take a backup if issues.db has data dump.
if (issue_db().execute('select count(*) from webcompat_issues')
.fetchall()[0][0] > 0):
if not os.path.exists(app.config['BACKUP_DEFAULT_DEST']):
print('Creating backup directory at {}').format(
os.path.join(app.config['BASE_DIR'], 'issues.db'))
os.makedirs(app.config['BACKUP_DEFAULT_DEST'])
time_stamp = time.strftime('%Y-%m-%dT%H-%M-%S', time.localtime())
issue_backup_db = 'issues_' + time_stamp + '.db'
os.rename(os.getcwd() + '/issues.db',
app.config['BACKUP_DEFAULT_DEST'] + issue_backup_db)
# Retain last 3 recent backup files
backup_files = os.listdir(app.config['BACKUP_DEFAULT_DEST'])
backup_files.sort()
for old_file in backup_files[:-3]:
os.remove(app.config['BACKUP_DEFAULT_DEST'] + old_file)
if check_pip_deps():
if not args.testmode:
# testing the config file.
# this file is only important in non-test mode.
# in test mode everything must be mocked,
# so there is no external api communication.
config_validator()
app.run(host='localhost')

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

else:
print('There is nothing to backup to ' +
app.config['BACKUP_DEFAULT_DEST'])
else:
if check_pip_deps():
# disable HttpOnly setting for session cookies so Selenium
# can interact with them. *ONLY* do this for testing.
app.config['SESSION_COOKIE_HTTPONLY'] = False
app.config['TESTING'] = True
print("Starting server in ~*TEST MODE*~")
app.run(host='localhost')
6 changes: 3 additions & 3 deletions webcompat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

'''This module powers the webcompat.com Flask application.'''
"""This module powers the webcompat.com Flask application."""

import logging

from flask import Flask
from flask_github import GitHub
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask import Flask

app = Flask(__name__, static_url_path='')
app.config.from_object('config')
Expand All @@ -25,7 +25,7 @@
limiter = Limiter(app, key_func=get_remote_address)

# import views after we initialize our github object
import webcompat.views
import webcompat.views # nopep8

# register blueprints
from api.endpoints import api
Expand Down
37 changes: 7 additions & 30 deletions webcompat/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

"""Databases initialization."""

from hashlib import sha512

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

import os
from uuid import uuid4

from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column
from sqlalchemy import String
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
from hashlib import sha512
from uuid import uuid4
from sqlalchemy import String

from webcompat import app

Expand All @@ -21,32 +24,6 @@
session_db = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=session_engine))

issue_engine = create_engine('sqlite:///' + os.path.join(
app.config['BASE_DIR'], 'issues.db'))
issue_db = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=issue_engine))
IssueBase = declarative_base()
IssueBase.query = issue_db.query_property()


class WCIssue(IssueBase):
__tablename__ = 'webcompat_issues'

issue_id = Column(String(128), unique=True, primary_key=True)
summary = Column(String(256))
url = Column(String(1024))
body = Column(String(2048))

def __init__(self, issue_id, summary, url, body):
self.issue_id = issue_id
self.summary = summary
self.url = url
self.body = body

IssueBase.metadata.create_all(bind=issue_engine)

UsersBase = declarative_base()
UsersBase.query = session_db.query_property()

Expand Down