Exemplo n.º 1
0
    def setUp(self):
        self.tmpdir = os.path.join(os.environ.get("WORKSPACE", ""), "tmp")
        self.addCleanup(clean_dir, self.tmpdir)
        if not os.path.isdir(self.tmpdir):
            os.makedirs(self.tmpdir)

        self.cmd = CliHandler()
        self.addCleanup(self.clean_ini)
Exemplo n.º 2
0
 def setUp(self):
     self.cmd = CliHandler()
     self.build_workspace = os.environ.get('WORKSPACE')
     self.tmpdir = None
     if self.build_workspace is not None:
         self.tmpdir = os.path.join(self.build_workspace, "tmp")
         if not os.path.isdir(self.tmpdir):
             os.makedirs(self.tmpdir)
Exemplo n.º 3
0
 def setUp(self):
     self.cmd = CliHandler()
     self.build_workspace = os.environ.get('WORKSPACE')
     self.tmpdir = None
     if self.build_workspace is not None:
         self.tmpdir = os.path.join(self.build_workspace, "tmp")
         if not os.path.isdir(self.tmpdir):
             os.makedirs(self.tmpdir)
Exemplo n.º 4
0
def cmd(tmp):
    path = tmp() / "config"
    path.mkdir(parents=True, exist_ok=True)
    Options.nxdrive_home = normalized_path(path)

    yield CliHandler()

    with suppress(FileNotFoundError):
        (Options.nxdrive_home / "config.ini").unlink()
Exemplo n.º 5
0
def main() -> int:
    """ Entry point. """

    # Catch CTRL+C
    signal.signal(signal.SIGINT, signal_handler)

    ret = 0

    try:
        # XXX_PYTHON
        if sys.version_info < (3, 9, 1):
            raise RuntimeError(f"{APP_NAME} requires Python 3.9.1+")

        # NXDRIVE-2230: Ensure the OS locale will be respected through the application
        locale.setlocale(locale.LC_TIME, "")

        if not (check_executable_path() and check_os_version()):
            return 1

        from sentry_sdk import configure_scope

        from nxdrive.commandline import CliHandler
        from nxdrive.tracing import setup_sentry
        from nxdrive.utils import get_current_os

        # Setup Sentry even if the user did not allow it because it can be tweaked
        # later via the "use-sentry" parameter. It will be useless if Sentry is not installed first.
        setup_sentry()

        with configure_scope() as scope:
            # Append OS and Python versions to all events
            # pylint: disable=protected-access
            os_name, os_version = get_current_os()
            scope._contexts.update({
                "runtime": {
                    "name": "Python",
                    "version": platform.python_version()
                },
                "os": {
                    "name": os_name,
                    "version": os_version
                },
            })

            ret = CliHandler().handle(sys.argv[1:])
    except SystemExit as exc:
        if exc.code != 0:
            show_critical_error()
        ret = exc.code
    except Exception:
        show_critical_error()
        ret = 1

    return ret
Exemplo n.º 6
0
def main() -> int:
    """ Entry point. """

    if sys.version_info < (3, 6):
        raise RuntimeError("Nuxeo Drive requires Python 3.6+")

    try:
        from nxdrive.commandline import CliHandler

        return CliHandler().handle(sys.argv)
    except:
        show_critical_error()
        return 1
Exemplo n.º 7
0
class CommandLineTestCase(unittest.TestCase):
    def setUp(self):
        self.cmd = CliHandler()
        self.build_workspace = os.environ.get('WORKSPACE')
        self.tmpdir = None
        if self.build_workspace is not None:
            self.tmpdir = os.path.join(self.build_workspace, "tmp")
            if not os.path.isdir(self.tmpdir):
                os.makedirs(self.tmpdir)

    def create_ini(self, filename='config.ini', env='PROD'):
        with open(filename, 'w+') as inifile:
            inifile.writelines(['[DEFAULT]\n',
                            'env=' + env + '\n',
                            '[PROD]\n',
                            'log-level-console=PROD\n',
                            '[DEV]\n',
                            'log-level-console=DEV\n'])

    def clean_ini(self, filename='config.ini'):
        if os.path.exists(filename):
            os.remove(filename)

    def test_update_site_url(self):
        argv = ["ndrive", "console", "--update-site-url", "DEBUG_TEST"]
        options = self.cmd.parse_cli([])
        self.assertEqual(options.update_site_url,
                         "http://community.nuxeo.com/static/drive/",
                         "The official default")
        # Normal arg
        options = self.cmd.parse_cli(argv)
        self.assertEqual(options.update_site_url, "DEBUG_TEST",
                            "Should be debug test")

    def test_default_override(self):
        self.cmd.default_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        try:
            self.clean_ini()
            argv = ["ndrive", "console", "--log-level-console", "DEBUG_TEST"]
            # Default value
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "INFO",
                                "The official default is INFO")
            # Normal arg
            options = self.cmd.parse_cli(argv)
            self.assertEqual(options.log_level_console, "DEBUG_TEST",
                                "Should be debug test")
            # config.ini override
            self.create_ini()
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "PROD",
                                "The config.ini shoud link to PROD")
            # config.ini override, but arg specified
            options = self.cmd.parse_cli(argv)
            self.assertEqual(options.log_level_console, "DEBUG_TEST",
                                "Should be debug test")
            # other usage section
            self.create_ini(env='DEV')
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "DEV",
                                "The config.ini shoud link to DEV")
            # user config.ini override
            conf = os.path.join(self.cmd.default_home, 'config.ini')
            self.create_ini(conf, "PROD")
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "PROD",
                                "The config.ini shoud link to PROD")
            self.clean_ini(conf)
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "DEV",
                                "The config.ini shoud link to DEV")
            self.clean_ini()
        finally:
            clean_dir(self.cmd.default_home)
Exemplo n.º 8
0
class CommandLineTestCase(unittest.TestCase):
    def setUp(self):
        self.tmpdir = os.path.join(os.environ.get("WORKSPACE", ""), "tmp")
        self.addCleanup(clean_dir, self.tmpdir)
        if not os.path.isdir(self.tmpdir):
            os.makedirs(self.tmpdir)

        self.cmd = CliHandler()
        self.addCleanup(self.clean_ini)

    def create_ini(self, filename="config.ini", env="PROD"):
        with open(filename, "w+") as inifile:
            inifile.writelines("""
[DEFAULT]
env = %s

[PROD]
log-level-console = TRACE
debug = False

[DEV]
log_level-console = ERROR
delay = 3
""" % env)

    def create_ini_bad(self, filename="config.ini"):
        with open(filename, "w+") as inifile:
            inifile.writelines("""
[DEFAULT]
env = bad

[bad]
log-level-console = TRACE
 debug = False

delay = 3
""")

    def clean_ini(self, filename="config.ini"):
        try:
            os.remove(filename)
        except OSError:
            pass

    @Options.mock()
    def test_update_site_url(self):
        Options.nxdrive_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        argv = ["ndrive", "console", "--update-site-url", "DEBUG_TEST"]
        options = self.cmd.parse_cli([])
        assert options.update_site_url == Options.update_site_url

        # Normal arg
        options = self.cmd.parse_cli(argv)
        assert options.update_site_url == "DEBUG_TEST"

    @Options.mock()
    def test_system_default(self):
        Options.nxdrive_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        original = AbstractOSIntegration.get
        AbstractOSIntegration.get = staticmethod(getOSIntegration)
        try:
            self.clean_ini()
            argv = ["ndrive", "console", "--log-level-console", "WARNING"]
            # Default value
            options = self.cmd.parse_cli([])
            assert options.log_level_console == "SYSTEM_TEST"

            # Normal arg
            options = self.cmd.parse_cli(argv)
            assert options.log_level_console == "WARNING"
        finally:
            AbstractOSIntegration.get = staticmethod(original)

    @Options.mock()
    def test_default_override(self):
        Options.nxdrive_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        self.clean_ini()
        argv = ["ndrive", "console", "--log-level-console=WARNING"]

        # Default value
        options = self.cmd.parse_cli([])
        assert options.log_level_console == "INFO"

        # Normal arg
        options = self.cmd.parse_cli(argv)
        assert options.log_level_console == "WARNING"

        # config.ini override
        self.create_ini()
        options = self.cmd.parse_cli([])
        assert options.log_level_console == "TRACE"
        self.clean_ini()

        # config.ini override, but arg specified
        options = self.cmd.parse_cli(argv)
        assert options.log_level_console == "WARNING"

        # other usage section
        self.create_ini(env="DEV")
        options = self.cmd.parse_cli([])
        assert options.log_level_console == "ERROR"
        self.clean_ini()

    @Options.mock()
    def test_malformatted_line(self):
        Options.nxdrive_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        self.clean_ini()

        # config.ini override
        self.create_ini_bad()
        options = self.cmd.parse_cli([])
        assert options.log_level_console == "TRACE"
        assert options.delay == 3
        self.clean_ini()
Exemplo n.º 9
0
def cmd(tmp):
    path = tmp() / "config"
    path.mkdir(parents=True, exist_ok=True)
    Options.nxdrive_home = normalized_path(path)

    yield CliHandler()
Exemplo n.º 10
0
class CommandLineTestCase(unittest.TestCase):
    def setUp(self):
        self.cmd = CliHandler()
        self.build_workspace = os.environ.get('WORKSPACE')
        self.tmpdir = None
        if self.build_workspace is not None:
            self.tmpdir = os.path.join(self.build_workspace, "tmp")
            if not os.path.isdir(self.tmpdir):
                os.makedirs(self.tmpdir)

    def create_ini(self, filename='config.ini', env='PROD'):
        with open(filename, 'w+') as inifile:
            inifile.writelines([
                '[DEFAULT]\n', 'env=' + env + '\n', '[PROD]\n',
                'log-level-console=PROD\n', '[DEV]\n',
                'log-level-console=DEV\n'
            ])

    def clean_ini(self, filename='config.ini'):
        if os.path.exists(filename):
            os.remove(filename)

    def test_update_site_url(self):
        argv = ["ndrive", "console", "--update-site-url", "DEBUG_TEST"]
        options = self.cmd.parse_cli([])
        self.assertEqual(options.update_site_url,
                         "http://community.nuxeo.com/static/drive/",
                         "The official default")
        # Normal arg
        options = self.cmd.parse_cli(argv)
        self.assertEqual(options.update_site_url, "DEBUG_TEST",
                         "Should be debug test")

    def test_system_default(self):
        original = AbstractOSIntegration.get
        AbstractOSIntegration.get = staticmethod(getOSIntegration)
        self.cmd.default_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        try:
            self.clean_ini()
            argv = ["ndrive", "console", "--log-level-console", "DEBUG_TEST"]
            # Default value
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "SYSTEM_TEST",
                             "The system default is SYSTEM_TEST")
            # Normal arg
            options = self.cmd.parse_cli(argv)
            self.assertEqual(options.log_level_console, "DEBUG_TEST",
                             "Should be debug test")
        finally:
            clean_dir(self.cmd.default_home)
            AbstractOSIntegration.get = staticmethod(original)

    def test_default_override(self):
        self.cmd.default_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        try:
            self.clean_ini()
            argv = ["ndrive", "console", "--log-level-console", "DEBUG_TEST"]
            # Default value
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "INFO",
                             "The official default is INFO")
            # Normal arg
            options = self.cmd.parse_cli(argv)
            self.assertEqual(options.log_level_console, "DEBUG_TEST",
                             "Should be debug test")
            # config.ini override
            self.create_ini()
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "PROD",
                             "The config.ini shoud link to PROD")
            # config.ini override, but arg specified
            options = self.cmd.parse_cli(argv)
            self.assertEqual(options.log_level_console, "DEBUG_TEST",
                             "Should be debug test")
            # other usage section
            self.create_ini(env='DEV')
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "DEV",
                             "The config.ini shoud link to DEV")
            # user config.ini override
            conf = os.path.join(self.cmd.default_home, 'config.ini')
            self.create_ini(conf, "PROD")
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "PROD",
                             "The config.ini shoud link to PROD")
            self.clean_ini(conf)
            options = self.cmd.parse_cli([])
            self.assertEqual(options.log_level_console, "DEV",
                             "The config.ini shoud link to DEV")
            self.clean_ini()
        finally:
            clean_dir(self.cmd.default_home)
Exemplo n.º 11
0
class CommandLineTestCase(unittest.TestCase):
    def setUp(self):
        self.tmpdir = os.path.join(os.environ.get('WORKSPACE', ''), 'tmp')
        self.addCleanup(clean_dir, self.tmpdir)
        if not os.path.isdir(self.tmpdir):
            os.makedirs(self.tmpdir)

        self.cmd = CliHandler()
        self.addCleanup(self.clean_ini)

    def create_ini(self, filename='config.ini', env='PROD'):
        with open(filename, 'w+') as inifile:
            inifile.writelines("""
[DEFAULT]
env = %s

[PROD]
log-level-console = TRACE
debug = False

[DEV]
log-level-console = ERROR
delay = 3
""" % env)

    def clean_ini(self, filename='config.ini'):
        try:
            os.remove(filename)
        except OSError:
            pass

    @Options.mock()
    def test_update_site_url(self):
        argv = ["ndrive", "console", "--update-site-url", "DEBUG_TEST"]
        options = self.cmd.parse_cli([])
        assert options.update_site_url == 'http://community.nuxeo.com/static/drive/'

        # Normal arg
        options = self.cmd.parse_cli(argv)
        assert options.update_site_url == 'DEBUG_TEST'

    @Options.mock()
    def test_system_default(self):
        self.cmd.default_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        original = AbstractOSIntegration.get
        AbstractOSIntegration.get = staticmethod(getOSIntegration)
        try:
            self.clean_ini()
            argv = ["ndrive", "console", "--log-level-console", "WARNING"]
            # Default value
            options = self.cmd.parse_cli([])
            assert options.log_level_console == 'SYSTEM_TEST'

            # Normal arg
            options = self.cmd.parse_cli(argv)
            assert options.log_level_console == 'WARNING'
        finally:
            AbstractOSIntegration.get = staticmethod(original)

    @Options.mock()
    def test_default_override(self):
        self.cmd.default_home = tempfile.mkdtemp("config", dir=self.tmpdir)
        self.clean_ini()
        argv = ['ndrive', 'console', '--log-level-console=WARNING']

        # Default value
        options = self.cmd.parse_cli([])
        assert options.log_level_console == 'INFO'

        # Normal arg
        options = self.cmd.parse_cli(argv)
        assert options.log_level_console == 'WARNING'

        # config.ini override
        self.create_ini()
        options = self.cmd.parse_cli([])
        assert options.log_level_console == 'TRACE'
        self.clean_ini()

        # config.ini override, but arg specified
        options = self.cmd.parse_cli(argv)
        assert options.log_level_console == 'WARNING'

        # other usage section
        self.create_ini(env='DEV')
        options = self.cmd.parse_cli([])
        assert options.log_level_console == 'ERROR'
        self.clean_ini()
Exemplo n.º 12
0
 def setUp(self):
     self.cmd = CliHandler()
Exemplo n.º 13
0
 def setUp(self):
     self.cmd = CliHandler()
Exemplo n.º 14
0
class CommandLineTestCase(unittest.TestCase):
    def setUp(self):
        self.cmd = CliHandler()

    def create_ini(self, filename='config.ini', env='PROD'):
        with open(filename, 'w+') as inifile:
            inifile.writelines([
                '[DEFAULT]\n', 'env=' + env + '\n', '[PROD]\n',
                'log-level-console=PROD\n', '[DEV]\n',
                'log-level-console=DEV\n'
            ])

    def clean_ini(self, filename='config.ini'):
        if os.path.exists(filename):
            os.remove(filename)

    def test_update__site_url(self):
        argv = ["ndrive", "--update-site-url", "DEBUG_TEST", "console"]
        options = self.cmd.parse_cli([])
        self.assertEqual(options.update_site_url,
                         "http://community.nuxeo.com/static/drive/",
                         "The official default")
        # Normal arg
        options = self.cmd.parse_cli(argv)
        self.assertEqual(options.update_site_url, "DEBUG_TEST",
                         "Should be debug test")

    def test_default_override(self):
        self.clean_ini()
        argv = ["ndrive", "--log-level-console", "DEBUG_TEST", "console"]
        # Default value
        options = self.cmd.parse_cli([])
        self.assertEqual(options.log_level_console, "INFO",
                         "The official default is INFO")
        # Normal arg
        options = self.cmd.parse_cli(argv)
        self.assertEqual(options.log_level_console, "DEBUG_TEST",
                         "Should be debug test")
        # config.ini override
        self.create_ini()
        options = self.cmd.parse_cli([])
        self.assertEqual(options.log_level_console, "PROD",
                         "The config.ini shoud link to PROD")
        # config.ini override, but arg specified
        options = self.cmd.parse_cli(argv)
        self.assertEqual(options.log_level_console, "DEBUG_TEST",
                         "Should be debug test")
        # other usage section
        self.create_ini(env='DEV')
        options = self.cmd.parse_cli([])
        self.assertEqual(options.log_level_console, "DEV",
                         "The config.ini shoud link to DEV")
        # user config.ini override
        self.cmd.default_home = tempfile.mkdtemp("config")
        conf = os.path.join(self.cmd.default_home, 'config.ini')
        self.create_ini(conf, "PROD")
        options = self.cmd.parse_cli([])
        self.assertEqual(options.log_level_console, "PROD",
                         "The config.ini shoud link to PROD")
        self.clean_ini(conf)
        options = self.cmd.parse_cli([])
        self.assertEqual(options.log_level_console, "DEV",
                         "The config.ini shoud link to DEV")
        self.clean_ini()