Skip to content

Commit

Permalink
[TASK] Basic cleanup of code base
Browse files Browse the repository at this point in the history
Removed parts of code that were extraneous to make code cleaner.
  • Loading branch information
shad7 committed Jun 1, 2015
1 parent 10e5678 commit cdf06bb
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[run]
branch = True
source = seedbox
omit = seedbox/tests/*, seedbox/db/admin.py, seedbox/db/sqlalchemy/migrate_repo/manage.py, seedbox/torrent/bencode.py
omit = seedbox/tests/*, seedbox/db/admin.py, seedbox/db/sqlalchemy/migrate_repo/*, seedbox/torrent/bencode.py

[report]
ignore-errors = True
Expand Down
2 changes: 1 addition & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# General information about the project.
project = u'seedbox'
copyright = u'2014, shad7'
copyright = u'2015, shad7'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
7 changes: 2 additions & 5 deletions seedbox/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@
The main program that is the entry point for the SeedboxManager application.
Provides the ability to configure and start up processing.
"""
from __future__ import absolute_import
import logging
import os
import sys

import lockfile
from lockfile import pidlockfile
from oslo_config import cfg

Expand All @@ -27,7 +24,7 @@ def main():
# processes all command-line inputs that control how we execute
# logging, run mode, etc.; and we get a handle back to access
# the info
options.initialize(sys.argv[1:])
options.initialize()

# configure our logging
logmgr.configure()
Expand All @@ -45,7 +42,7 @@ def main():
# time to start processing
process.start()

except lockfile.LockTimeout as lockerr:
except pidlockfile.LockTimeout as lockerr:
# if we have managed timeout, it means there is another instance
# already running so we will simply bow out and let the existing
# one still run.
Expand Down
5 changes: 2 additions & 3 deletions seedbox/db/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from sandman import model

from seedbox import options
from seedbox import version


def load_passfile():
Expand All @@ -28,6 +27,8 @@ def load_passfile():

@sandman.auth.verify_password
def verify_password(username, password):
if username != 'admin':
return False
pw = None
with open(load_passfile(), 'r') as fd:
pw = fd.read()
Expand Down Expand Up @@ -64,8 +65,6 @@ def save_password(password):
help='Port of database server to connect to')
@click.option('--debug', default=False,
help='Enable debug output from webserver')
@click.version_option(version=version.version_string(),
message='SeedboxManager v%(version)s')
@click.argument('URI', metavar='<URI>')
def run(generate_pks, show_pks, host, port, debug, uri):
"""Start the admin UI for managing data
Expand Down
60 changes: 20 additions & 40 deletions seedbox/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
manages loading all Options for system.
"""
import os
import sys

from oslo_config import cfg
from six import moves

from seedbox import version

PROJECT_NAME = 'seedbox'
PROJECT = __package__
DEFAULT_FILENAME = PROJECT + '.conf'

OPTS = [
cfg.StrOpt('base_path',
Expand All @@ -27,48 +27,28 @@

def _find_config_files():

virtual_path = os.getenv('VIRTUAL_ENV')
default_cfg_type = '.conf'
legacy_cfg_type = '.cfg'

possible = []
# in reverse order as the last one loaded always takes precedence
# system-level /etc and /etc/<project>
possible.append(os.sep + 'etc')
possible.append(os.path.join(os.sep, 'etc', PROJECT_NAME))

# if virtualenv is active; then leverage <virtualenv>/etc
# and <virtualenv>/etc/<project>
if virtual_path:
possible.append(os.path.join(virtual_path, 'etc'))
possible.append(os.path.join(virtual_path, 'etc', PROJECT_NAME))

# the user's home directory
possible.append(os.path.expanduser('~'))

# the user's home directory with project specific directory
possible.append(os.path.join(os.path.expanduser('~'), '.' + PROJECT_NAME))
if sys.platform.startswith('win'):
# On windows look in ~/seedbox as well, as explorer does not
# let you create a folder starting with a dot
possible.append(os.path.join(os.path.expanduser('~'), PROJECT_NAME))

# current working directory as a last ditch effort
possible.append(os.getcwd())

# now append the filename to the possible locations we search
config_files = []
for loc in possible:
config_files.append(
os.path.join(loc, PROJECT_NAME + default_cfg_type))
config_files.append(
os.path.join(loc, PROJECT_NAME + legacy_cfg_type))
def _fixpath(p):
"""Apply tilde expansion and absolutization to a path."""
return os.path.abspath(os.path.expanduser(p))

virtual_env = os.environ.get('VIRTUAL_ENV', '')

config_files = [
_fixpath(os.path.join('~', '.' + PROJECT, DEFAULT_FILENAME)),
_fixpath(os.path.join('~', DEFAULT_FILENAME)),
os.path.join(os.sep + 'etc', PROJECT, DEFAULT_FILENAME),
os.path.join(os.sep + 'etc', DEFAULT_FILENAME),
os.path.join(PROJECT, 'etc', PROJECT, DEFAULT_FILENAME),
os.path.join(virtual_env, 'etc', PROJECT, DEFAULT_FILENAME),
os.path.join(virtual_env, 'etc', DEFAULT_FILENAME),
os.path.join(os.getcwd(), DEFAULT_FILENAME)
]

# return back the list of the config files found
return list(moves.filter(os.path.exists, config_files))


def initialize(args):
def initialize(args=None):
"""Initialize options.
Handles finding and loading configuration options for the entire
Expand All @@ -93,7 +73,7 @@ def initialize(args):
# configure the program to start....
cfg.CONF(
args,
project=PROJECT_NAME,
project=PROJECT,
version=version.version_string(),
default_config_files=_find_config_files(),
)
Expand Down
2 changes: 1 addition & 1 deletion seedbox/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class FakeOptions(object):

@staticmethod
def initialize(args):
def initialize(args=None):
pass


Expand Down
18 changes: 0 additions & 18 deletions seedbox/tests/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,3 @@ def test_without_venv(self):

cfg.CONF.reset()
self._delete_cfg_file(location)

def test_for_windows_home(self):

location = os.path.join(os.path.expanduser('~'), options.PROJECT_NAME)

with fixtures.MonkeyPatch('sys.platform', 'win'):

self._write_cfg_file(location)

self.assertTrue(os.path.exists(
os.path.join(location, self.CFG_FILE)))

options.initialize([])
self.assertIsNotNone(cfg.CONF.config_file)
self.assertEqual(cfg.CONF.config_dir, location)

cfg.CONF.reset()
self._delete_cfg_file(location)

0 comments on commit cdf06bb

Please sign in to comment.