From 1ce2f6fe70fbcf64b677ee0e37dee2627a88038a Mon Sep 17 00:00:00 2001 From: spl0k Date: Sun, 16 Jun 2019 16:02:50 +0200 Subject: [PATCH] Changed the way the CLI is installed --- bin/supysonic-cli | 23 +++++++---------------- setup.py | 6 ++++-- supysonic/cli.py | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 19 deletions(-) mode change 100644 => 100755 supysonic/cli.py diff --git a/bin/supysonic-cli b/bin/supysonic-cli index c63ff57..6f8a99e 100755 --- a/bin/supysonic-cli +++ b/bin/supysonic-cli @@ -8,21 +8,12 @@ # # Distributed under terms of the GNU AGPLv3 license. -import sys - -from supysonic.cli import SupysonicCLI -from supysonic.config import IniConfig -from supysonic.db import init_database, release_database +import warnings +from supysonic.cli import main if __name__ == "__main__": - config = IniConfig.from_common_locations() - init_database(config.BASE['database_uri']) - - cli = SupysonicCLI(config) - if len(sys.argv) > 1: - cli.onecmd(' '.join(sys.argv[1:])) - else: - cli.cmdloop() - - release_database() - + warnings.warn( + "You're using an old version of the `supysonic-cli` script. " + "It should have been replaced on install." + ) + main() diff --git a/setup.py b/setup.py index 2c8bf92..49187d7 100755 --- a/setup.py +++ b/setup.py @@ -37,8 +37,10 @@ setup( license=project.LICENSE, packages=find_packages(exclude=['tests*']), install_requires = reqs, - scripts=['bin/supysonic-cli'], - entry_points={ 'console_scripts': ['supysonic-daemon=supysonic.daemon:main'] }, + entry_points={ 'console_scripts': [ + 'supysonic-cli=supysonic.cli:main', + 'supysonic-daemon=supysonic.daemon:main' + ] }, zip_safe=False, include_package_data=True, test_suite='tests.suite', diff --git a/supysonic/cli.py b/supysonic/cli.py old mode 100644 new mode 100755 index 75917df..7d444d5 --- a/supysonic/cli.py +++ b/supysonic/cli.py @@ -16,9 +16,10 @@ import time from pony.orm import db_session, select from pony.orm import ObjectNotFound +from .config import IniConfig from .daemon.client import DaemonClient from .daemon.exceptions import DaemonUnavailableError -from .db import Folder, User +from .db import Folder, User, init_database, release_database from .managers.folder import FolderManager from .managers.user import UserManager from .scanner import Scanner @@ -293,3 +294,17 @@ class SupysonicCLI(cmd.Cmd): except ObjectNotFound as e: self.write_error_line(str(e)) +def main(): + config = IniConfig.from_common_locations() + init_database(config.BASE['database_uri']) + + cli = SupysonicCLI(config) + if len(sys.argv) > 1: + cli.onecmd(' '.join(sys.argv[1:])) + else: + cli.cmdloop() + + release_database() + +if __name__ == "__main__": + main()