Esempio n. 1
0
    def clean_tool(self):
        """Checks the SCMTool used for this repository for dependencies.

        If one or more dependencies aren't found, they will be presented
        as validation errors.
        """
        tool = self.cleaned_data["tool"]
        scmtool_class = tool.get_scmtool_class()

        errors = []

        for dep in scmtool_class.dependencies.get("modules", []):
            if not has_module(dep):
                errors.append(
                    _(
                        'The Python module "%s" is not installed. '
                        "You may need to restart the server "
                        "after installing it."
                    )
                    % dep
                )

        for dep in scmtool_class.dependencies.get("executables", []):
            if not is_exe_in_path(dep):
                if sys.platform == "win32":
                    exe_name = "%s.exe" % dep
                else:
                    exe_name = dep

                errors.append(_('The executable "%s" is not in the path.') % exe_name)

        if errors:
            raise ValidationError(errors)

        return tool
Esempio n. 2
0
def get_can_enable_dns():
    """Check whether we can query DNS to find the domain controller to use."""
    if has_module('DNS'):
        return (True, None)
    else:
        return (False,
                _('PyDNS, which is required to find the domain controller, '
                  'is not installed.'))
Esempio n. 3
0
def get_can_use_couchdb():
    """Checks whether django-storages (CouchDB backend) is installed."""
    if has_module('storages.backends.couchdb', members=['CouchDBStorage']):
        return (True, None)
    else:
        return (False, _(
            'CouchDB depends on django-storages, which is not installed'
        ))
Esempio n. 4
0
def get_can_use_couchdb():
    """Check whether django-storages (CouchDB backend) is installed."""
    if has_module('storages.backends.couchdb', members=['CouchDBStorage']):
        return (True, None)
    else:
        return (
            False,
            _('CouchDB depends on django-storages, which is not installed'))
Esempio n. 5
0
def get_can_enable_ldap():
    """Check whether LDAP authentication can be enabled."""
    if has_module('ldap'):
        return (True, None)
    else:
        return (
            False,
            _('LDAP authentication requires the python-ldap library, which '
              'is not installed.'))
Esempio n. 6
0
def get_can_use_amazon_s3():
    """Checks whether django-storages (Amazon S3 backend) is installed."""
    try:
        if has_module("storages.backends.s3boto", members=["S3BotoStorage"]):
            return (True, None)
        else:
            return (False, _("Amazon S3 depends on django-storages, which is not installed"))
    except ImproperlyConfigured as e:
        return (False, _("Amazon S3 backend failed to load: %s") % e)
Esempio n. 7
0
def get_can_enable_dns():
    """Checks whether we can query DNS to find the domain controller to use."""
    if has_module('DNS'):
        return (True, None)
    else:
        return (False, _(
            'PyDNS, which is required to find the domain controller, '
            'is not installed.'
        ))
Esempio n. 8
0
def get_can_enable_ldap():
    """Checks whether LDAP authentication can be enabled."""
    if has_module('ldap'):
        return (True, None)
    else:
        return (False, _(
            'LDAP authentication requires the python-ldap library, which '
            'is not installed.'
        ))
Esempio n. 9
0
def get_can_use_openstack_swift():
    """Check whether django-storage-swift is installed."""
    try:
        if has_module("swift.storage", members=["SwiftStorage"]):
            return (True, None)
        else:
            return (False, _("OpenStack Swift depends on django-storage-swift, " "which is not installed"))
    except ImproperlyConfigured as e:
        return (False, _("OpenStack Swift backend failed to load: %s") % e)
Esempio n. 10
0
    def test_create_with_parser_get_orig_commit_id(self):
        """Testing UploadDiffForm.create uses correct base revision returned
        by DiffParser.get_orig_commit_id
        """
        diff = (
            b'# Node ID a6fc203fee9091ff9739c9c00cd4a6694e023f48\n'
            b'# Parent  7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
            b'diff --git a/doc/readme b/doc/readme\n'
            b'--- a/doc/readme\n'
            b'+++ b/doc/readme\n'
            b'@@ -1,3 +1,3 @@\n'
            b' Hello\n'
            b'-\n'
            b'+...\n'
            b' goodbye\n'
        )

        parent_diff = (
            b'# Node ID 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
            b'# Parent  661e5dd3c4938ecbe8f77e2fdfa905d70485f94c\n'
            b'diff --git a/doc/newfile b/doc/newfile\n'
            b'new file mode 100644\n'
            b'--- /dev/null\n'
            b'+++ b/doc/newfile\n'
            b'@@ -0,0 +1,1 @@\n'
            b'+Lorem ipsum\n'
        )

        if not has_module('mercurial'):
            raise nose.SkipTest("Hg is not installed")

        diff_file = SimpleUploadedFile('diff', diff,
                                       content_type='text/x-patch')
        parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
                                              content_type='text/x-patch')

        repository = Repository.objects.create(
            name='Test HG',
            path='scmtools/testdata/hg_repo',
            tool=Tool.objects.get(name='Mercurial'))

        form = UploadDiffForm(
            repository=repository,
            files={
                'path': diff_file,
                'parent_diff_path': parent_diff_file,
            })
        self.assertTrue(form.is_valid())

        diffset = form.create()
        self.assertEqual(diffset.files.count(), 1)

        filediff = diffset.files.get()

        self.assertEqual(filediff.source_revision,
                         '661e5dd3c4938ecbe8f77e2fdfa905d70485f94c')
Esempio n. 11
0
    def test_create_with_parser_get_orig_commit_id(self):
        """Testing UploadDiffForm.create uses correct base revision returned
        by DiffParser.get_orig_commit_id
        """
        diff = (
            b'# Node ID a6fc203fee9091ff9739c9c00cd4a6694e023f48\n'
            b'# Parent  7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
            b'diff --git a/doc/readme b/doc/readme\n'
            b'--- a/doc/readme\n'
            b'+++ b/doc/readme\n'
            b'@@ -1,3 +1,3 @@\n'
            b' Hello\n'
            b'-\n'
            b'+...\n'
            b' goodbye\n'
        )

        parent_diff = (
            b'# Node ID 7c4735ef51a7c665b5654f1a111ae430ce84ebbd\n'
            b'# Parent  661e5dd3c4938ecbe8f77e2fdfa905d70485f94c\n'
            b'diff --git a/doc/newfile b/doc/newfile\n'
            b'new file mode 100644\n'
            b'--- /dev/null\n'
            b'+++ b/doc/newfile\n'
            b'@@ -0,0 +1,1 @@\n'
            b'+Lorem ipsum\n'
        )

        if not has_module('mercurial'):
            raise nose.SkipTest("Hg is not installed")

        diff_file = SimpleUploadedFile('diff', diff,
                                       content_type='text/x-patch')
        parent_diff_file = SimpleUploadedFile('parent_diff', parent_diff,
                                              content_type='text/x-patch')

        repository = Repository.objects.create(
            name='Test HG',
            path='scmtools/testdata/hg_repo',
            tool=Tool.objects.get(name='Mercurial'))

        form = UploadDiffForm(
            repository=repository,
            files={
                'path': diff_file,
                'parent_diff_path': parent_diff_file,
            })
        self.assertTrue(form.is_valid())

        diffset = form.create()
        self.assertEqual(diffset.files.count(), 1)

        filediff = diffset.files.get()

        self.assertEqual(filediff.source_revision,
                         '661e5dd3c4938ecbe8f77e2fdfa905d70485f94c')
Esempio n. 12
0
def get_can_use_openstack_swift():
    """Check whether django-storage-swift is installed."""
    try:
        if has_module('swift.storage', members=['SwiftStorage']):
            return (True, None)
        else:
            return (False,
                    _('OpenStack Swift depends on django-storage-swift, '
                      'which is not installed'))
    except ImproperlyConfigured as e:
        return (False, _('OpenStack Swift backend failed to load: %s') % e)
Esempio n. 13
0
def get_can_use_amazon_s3():
    """Checks whether django-storages (Amazon S3 backend) is installed."""
    try:
        if has_module('storages.backends.s3boto', members=['S3BotoStorage']):
            return (True, None)
        else:
            return (False, _(
                'Amazon S3 depends on django-storages, which is not installed'
            ))
    except ImproperlyConfigured as e:
        return (False, _('Amazon S3 backend failed to load: %s') % e)
Esempio n. 14
0
def get_can_enable_ldap():
    """Check whether LDAP authentication can be enabled.

    Returns:
        tuple:
        A tuple containing:

        1. A boolean indicating whether the support can be enabled.
        2. A localized string explaining how to enable the support, or ``None``
           if support is available.
    """
    if has_module('ldap'):
        return True, None
    else:
        return (
            False,
            _('To enable support for LDAP and Active Directory, you will need '
              'to install the ReviewBoard[ldap] module (e.g., `pip install '
              'ReviewBoard[ldap]`).'))
Esempio n. 15
0
def check_dependencies(settings):
    # We're now safe to import anything that might touch Django settings,
    # such as code utilizing the database. Start importing what we need for
    # dependency checks.
    from djblets.util.filesystem import is_exe_in_path

    from reviewboard.admin.import_utils import has_module
    from reviewboard.dependencies import (dependency_error,
                                          dependency_warning,
                                          fail_if_missing_dependencies)

    # Make sure the correct version of Python is being used. This should be
    # covered by setup.py, but it's best to make sure here.
    if sys.version_info[0] != 2 or sys.version_info[1] != 7:
        dependency_error('Python 2.7 is required.')

    # Check for NodeJS and installed modules, to make sure these weren't
    # missed during installation.
    if not is_exe_in_path('node'):
        dependency_error('node (from NodeJS) was not found. It must be '
                         'installed from your package manager or from '
                         'https://nodejs.org/')

    if not os.path.exists('node_modules'):
        dependency_error('The node_modules directory is missing. Please '
                         're-run `./setup.py develop` to install all NodeJS '
                         'dependencies.')

    for key in ('UGLIFYJS_BINARY', 'LESS_BINARY', 'BABEL_BINARY'):
        path = settings.PIPELINE[key]

        if not os.path.exists(path):
            dependency_error('%s is missing. Please re-run `./setup.py '
                             'develop` to install all NodeJS dependencies.'
                             % os.path.abspath(path))

    # The following checks are non-fatal warnings, since these dependencies
    # are merely recommended, not required. These are primarily for SCM
    # support.
    if not has_module('pysvn') and not has_module('subvertpy'):
        dependency_warning('Neither the subvertpy nor pysvn Python modules '
                           'were found. Subversion integration will not work. '
                           'For pysvn, see your package manager for the '
                           'module or download from '
                           'http://pysvn.tigris.org/project_downloads.html. '
                           'For subvertpy, run `pip install subvertpy`. We '
                           'recommend pysvn for better compatibility.')

    if has_module('P4'):
        try:
            subprocess.call(['p4', '-h'],
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        except OSError:
            dependency_warning('The p4 command not found. Perforce '
                               'integration will not work. To enable support, '
                               'download p4 from '
                               'http://cdist2.perforce.com/perforce/ and '
                               'place it in your PATH.')
    else:
        dependency_warning('The p4python module was not found. Perforce '
                           'integration will not work. To enable support, '
                           'run `pip install p4python`')

    if not is_exe_in_path('hg'):
        dependency_warning('The hg command was not found. Mercurial '
                           'integration will not work. To enable support, '
                           'run `pip install mercurial`')

    if not is_exe_in_path('bzr'):
        dependency_warning('The bzr command was not found. Bazaar integration '
                           'will not work. To enable support, run '
                           '`pip install bzr`')

    if not is_exe_in_path('cvs'):
        dependency_warning('The cvs command was not found. CVS integration '
                           'will not work. To enable support, install cvs '
                           'from your package manager or from '
                           'http://www.nongnu.org/cvs/')

    if not is_exe_in_path('git'):
        dependency_warning('The git command not found. Git integration '
                           'will not work. To enable support, install git '
                           'from your package manager or from '
                           'https://git-scm.com/downloads')

    # Along with all those, Django will print warnings/errors for database
    # backend modules if the configuration requires it.
    #
    # Now that that's all done, check if anything was missing and, if so,
    # fail with some helpful text.
    fail_if_missing_dependencies()
Esempio n. 16
0
def check_dependencies(settings):
    # We're now safe to import anything that might touch Django settings,
    # such as code utilizing the database. Start importing what we need for
    # dependency checks.
    from djblets.util.filesystem import is_exe_in_path

    from reviewboard.admin.import_utils import has_module
    from reviewboard.dependencies import (dependency_error, dependency_warning,
                                          fail_if_missing_dependencies)

    # Make sure the correct version of Python is being used. This should be
    # covered by setup.py, but it's best to make sure here.
    pyver = sys.version_info[:2]

    if pyver < PYTHON_2_MIN_VERSION or (3, 0) <= pyver < PYTHON_3_MIN_VERSION:
        dependency_error('Python %s or %s+ is required.' %
                         (PYTHON_2_MIN_VERSION_STR, PYTHON_3_MIN_VERSION_STR))

    # Check for NodeJS and installed modules, to make sure these weren't
    # missed during installation.
    if not is_exe_in_path('node'):
        dependency_error('node (from NodeJS) was not found. It must be '
                         'installed from your package manager or from '
                         'https://nodejs.org/')

    if not os.path.exists('node_modules'):
        dependency_error('The node_modules directory is missing. Please '
                         're-run `./setup.py develop` to install all NodeJS '
                         'dependencies.')

    for key in ('UGLIFYJS_BINARY', 'LESS_BINARY', 'BABEL_BINARY'):
        path = settings.PIPELINE[key]

        if not os.path.exists(path):
            dependency_error('%s is missing. Please re-run `./setup.py '
                             'develop` to install all NodeJS dependencies.' %
                             os.path.abspath(path))

    # The following checks are non-fatal warnings, since these dependencies
    # are merely recommended, not required. These are primarily for SCM
    # support.
    if not has_module('pysvn') and not has_module('subvertpy'):
        dependency_warning('Neither the subvertpy nor pysvn Python modules '
                           'were found. Subversion integration will not work. '
                           'For pysvn, see your package manager for the '
                           'module or download from '
                           'http://pysvn.tigris.org/project_downloads.html. '
                           'For subvertpy, run `pip install subvertpy`. We '
                           'recommend pysvn for better compatibility.')

    if has_module('P4'):
        try:
            subprocess.call(['p4', '-h'],
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE)
        except OSError:
            dependency_warning('The p4 command not found. Perforce '
                               'integration will not work. To enable support, '
                               'download p4 from '
                               'http://cdist2.perforce.com/perforce/ and '
                               'place it in your PATH.')
    else:
        dependency_warning('The p4python module was not found. Perforce '
                           'integration will not work. To enable support, '
                           'run `pip install p4python`')

    if not is_exe_in_path('hg'):
        dependency_warning('The hg command was not found. Mercurial '
                           'integration will not work. To enable support, '
                           'run `pip install mercurial`')

    if not is_exe_in_path('bzr'):
        dependency_warning('The bzr command was not found. Bazaar integration '
                           'will not work. To enable support, run '
                           '`pip install bzr`')

    if not is_exe_in_path('cvs'):
        dependency_warning('The cvs command was not found. CVS integration '
                           'will not work. To enable support, install cvs '
                           'from your package manager or from '
                           'http://www.nongnu.org/cvs/')

    if not is_exe_in_path('git'):
        dependency_warning('The git command not found. Git integration '
                           'will not work. To enable support, install git '
                           'from your package manager or from '
                           'https://git-scm.com/downloads')

    # Along with all those, Django will print warnings/errors for database
    # backend modules if the configuration requires it.
    #
    # Now that that's all done, check if anything was missing and, if so,
    # fail with some helpful text.
    fail_if_missing_dependencies()
Esempio n. 17
0
def check_dependencies(settings):
    # Some of our checks require access to django.conf.settings, so
    # tell Django about our settings.
    #
    from djblets.util.filesystem import is_exe_in_path

    from reviewboard.admin.import_utils import has_module

    dependency_error = settings.dependency_error

    # Python 2.6
    if sys.version_info[0] < 2 or \
       (sys.version_info[0] == 2 and sys.version_info[1] < 6):
        dependency_error('Python 2.6 or newer is required.')

    # django-evolution
    if not has_module('django_evolution'):
        dependency_error("django_evolution is required.\n"
                         "http://code.google.com/p/django-evolution/")

    # PIL
    if not has_module('PIL') and not has_module('Image'):
        dependency_error('The Python Imaging Library (Pillow or PIL) '
                         'is required.')

    # The following checks are non-fatal warnings, since these dependencies are
    # merely recommended, not required.
    def dependency_warning(string):
        sys.stderr.write('Warning: %s\n' % string)
        global warnings_found
        warnings_found += 1

    if not has_module('pysvn') and not has_module('subvertpy'):
        dependency_warning('Neither subvertpy nor pysvn found. '
                           'SVN integration will not work.')

    if has_module('P4'):
        try:
            subprocess.call(['p4', '-h'],
                            stdin=subprocess.PIPE,
                            stdout=subprocess.PIPE)
        except OSError:
            dependency_error('p4 command not found. Perforce integration '
                             'will not work.')
    else:
        dependency_warning('p4python (>=07.3) not found. Perforce integration '
                           'will not work.')

    if not has_module('mercurial'):
        dependency_warning('hg not found. Mercurial integration will not '
                           'work.')

    if not has_module('bzrlib'):
        dependency_warning('bzrlib not found. Bazaar integration will not '
                           'work.')

    if not is_exe_in_path('cvs'):
        dependency_warning('cvs binary not found. CVS integration '
                           'will not work.')

    if not is_exe_in_path('git'):
        dependency_warning('git binary not found. Git integration '
                           'will not work.')

    if not is_exe_in_path('mtn'):
        dependency_warning('mtn binary not found. Monotone integration '
                           'will not work.')

    # Django will print warnings/errors for database backend modules and flup
    # if the configuration requires it.

    if warnings_found:
        sys.stderr.write(settings.install_help)
        sys.stderr.write('\n\n')
Esempio n. 18
0
def check_dependencies(settings):
    # Some of our checks require access to django.conf.settings, so
    # tell Django about our settings.
    #
    from djblets.util.filesystem import is_exe_in_path

    from reviewboard.admin.import_utils import has_module

    dependency_error = settings.dependency_error

    # Python 2.6
    if sys.version_info[0] < 2 or \
       (sys.version_info[0] == 2 and sys.version_info[1] < 6):
        dependency_error('Python 2.6 or newer is required.')

    # django-evolution
    if not has_module('django_evolution'):
        dependency_error("django_evolution is required.\n"
                         "http://code.google.com/p/django-evolution/")

    # PIL
    if not has_module('PIL') and not has_module('Image'):
        dependency_error('The Python Imaging Library (Pillow or PIL) '
                         'is required.')

    # ReCaptcha
    if not has_module('recaptcha'):
        dependency_error('The recaptcha python module is required.')

    # The following checks are non-fatal warnings, since these dependencies are
    # merely recommended, not required.
    def dependency_warning(string):
        sys.stderr.write('Warning: %s\n' % string)
        global warnings_found
        warnings_found += 1

    if not has_module('pysvn') and not has_module('subvertpy'):
        dependency_warning('Neither subvertpy nor pysvn found. '
                           'SVN integration will not work.')

    if has_module('P4'):
        try:
            subprocess.call(['p4', '-h'],
                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
        except OSError:
            dependency_error('p4 command not found. Perforce integration '
                             'will not work.')
    else:
        dependency_warning('p4python (>=07.3) not found. Perforce integration '
                           'will not work.')

    if not has_module('mercurial'):
        dependency_warning('hg not found. Mercurial integration will not '
                           'work.')

    if not has_module('bzrlib'):
        dependency_warning('bzrlib not found. Bazaar integration will not '
                           'work.')

    if not is_exe_in_path('cvs'):
        dependency_warning('cvs binary not found. CVS integration '
                           'will not work.')

    if not is_exe_in_path('git'):
        dependency_warning('git binary not found. Git integration '
                           'will not work.')

    if not is_exe_in_path('mtn'):
        dependency_warning('mtn binary not found. Monotone integration '
                           'will not work.')

    # Django will print warnings/errors for database backend modules and flup
    # if the configuration requires it.

    if warnings_found:
        sys.stderr.write(settings.install_help)
        sys.stderr.write('\n\n')