def test_get_config_directory(self):
        old_isfile = os.path.isfile
        old_isdir = os.path.isdir

        section = Section("default")

        # Without section
        config_dir = get_config_directory(None)
        self.assertEqual(config_dir, os.getcwd())

        # With section, but without "config"
        os.path.isfile = lambda *args: True
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, os.getcwd())

        os.path.isfile = lambda *args: False
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, None)

        # With "config" in section
        section.append(Setting("config", "/path/to/dir/config"))

        os.path.isdir = lambda *args: True
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, "/path/to/dir/config")

        os.path.isdir = lambda *args: False
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, "/path/to/dir")

        os.path.isdir = old_isdir
        os.path.isfile = old_isfile
Пример #2
0
    def test_get_config_directory(self):
        old_isfile = os.path.isfile
        old_isdir = os.path.isdir

        section = Section("default")

        # Without section
        config_dir = get_config_directory(None)
        self.assertEqual(config_dir, os.getcwd())

        # With section, but without "config"
        os.path.isfile = lambda *args: True
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, os.getcwd())

        os.path.isfile = lambda *args: False
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, None)

        # With "config" in section
        section.append(Setting("config", "/path/to/dir/config"))

        os.path.isdir = lambda *args: True
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, "/path/to/dir/config")

        os.path.isdir = lambda *args: False
        config_dir = get_config_directory(section)
        self.assertEqual(config_dir, "/path/to/dir")

        os.path.isdir = old_isdir
        os.path.isfile = old_isfile
Пример #3
0
def main(log_printer=None, section: Section = None):
    start_path = get_config_directory(section)
    log_printer = log_printer or LogPrinter(ConsolePrinter())

    if start_path is None:
        log_printer.err("Can only delete .orig files if .coafile is found")
        return 255

    orig_files = Globbing.glob(
        os.path.abspath(os.path.join(start_path, '**', '*.orig')))

    not_deleted = 0
    for ofile in orig_files:
        log_printer.info("Deleting old backup file... " +
                         os.path.relpath(ofile))
        try:
            os.remove(ofile)
        except OSError as oserror:
            not_deleted += 1
            log_printer.warn("Couldn't delete... {}. {}".format(
                os.path.relpath(ofile), oserror.strerror))

    if not_deleted:
        log_printer.warn(
            str(not_deleted) + " .orig backup files could not be"
            " deleted, possibly because you lack the permission"
            " to do so. coala may not be able to create"
            " backup files when patches are applied.")
    return 0
Пример #4
0
def main(log_printer=None, section: Section = None):
    configure_logging()

    start_path = get_config_directory(section)

    if start_path is None:
        return 255

    # start_path may have unintended glob characters
    orig_files = Globbing.glob(os.path.join(
        glob_escape(start_path), '**', '*.orig'))

    not_deleted = 0
    for ofile in orig_files:
        logging.info('Deleting old backup file... ' + os.path.relpath(ofile))
        try:
            os.remove(ofile)
        except OSError as oserror:
            not_deleted += 1
            logging.warning("Couldn't delete {}. {}".format(
                os.path.relpath(ofile), oserror.strerror))

    if not_deleted:
        logging.warning(str(not_deleted) + ' .orig backup files could not be'
                                           ' deleted, possibly because you '
                                           'lack the permission to do so. '
                                           'coala may not be able to create'
                                           ' backup files when patches are '
                                           'applied.')
    return 0
Пример #5
0
def main(log_printer=None, section: Section=None):
    start_path = get_config_directory(section)
    log_printer = log_printer or LogPrinter(ConsolePrinter())

    if start_path is None:
        return 255

    # start_path may have unintended glob characters
    orig_files = Globbing.glob(os.path.join(
        glob_escape(start_path), '**', '*.orig'))

    not_deleted = 0
    for ofile in orig_files:
        log_printer.info("Deleting old backup file... "
                         + os.path.relpath(ofile))
        try:
            os.remove(ofile)
        except OSError as oserror:
            not_deleted += 1
            log_printer.warn("Couldn't delete {}. {}".format(
                os.path.relpath(ofile), oserror.strerror))

    if not_deleted:
        log_printer.warn(str(not_deleted) + " .orig backup files could not be"
                         " deleted, possibly because you lack the permission"
                         " to do so. coala may not be able to create"
                         " backup files when patches are applied.")
    return 0
Пример #6
0
def main(log_printer=None, section: Section = None):
    configure_logging()

    start_path = get_config_directory(section)
    log_printer = (LogPrinter(ConsolePrinter())
                   if log_printer is None else log_printer)

    if start_path is None:
        return 255

    # start_path may have unintended glob characters
    orig_files = Globbing.glob(
        os.path.join(glob_escape(start_path), '**', '*.orig'))

    not_deleted = 0
    for ofile in orig_files:
        log_printer.info('Deleting old backup file... ' +
                         os.path.relpath(ofile))
        try:
            os.remove(ofile)
        except OSError as oserror:
            not_deleted += 1
            log_printer.warn("Couldn't delete {}. {}".format(
                os.path.relpath(ofile), oserror.strerror))

    if not_deleted:
        log_printer.warn(
            str(not_deleted) + ' .orig backup files could not be'
            ' deleted, possibly because you lack the permission'
            ' to do so. coala may not be able to create'
            ' backup files when patches are applied.')
    return 0
Пример #7
0
def main(log_printer=None, section: Section=None):
    start_path = get_config_directory(section)
    log_printer = log_printer or LogPrinter(ConsolePrinter())

    if start_path is None:
        log_printer.err("Can only delete .orig files if .coafile is found")
        return 255

    orig_files = Globbing.glob(os.path.abspath(
        os.path.join(start_path, '**', '*.orig')))

    not_deleted = 0
    for ofile in orig_files:
        log_printer.info("Deleting old backup file... "
                         + os.path.relpath(ofile))
        try:
            os.remove(ofile)
        except:
            not_deleted += 1
            log_printer.warn("Couldn't delete... " + os.path.relpath(ofile))

    if not_deleted:
        log_printer.warn(str(not_deleted) + " .orig backup files could not be"
                         " deleted, possibly because you lack the permission"
                         " to do so. coala may not be able to create"
                         " backup files when patches are applied.")
    return 0
Пример #8
0
    def get_config_dir(self):
        """
        Gives the directory where the configuration file is.

        :return: Directory of the config file.
        """
        return get_config_directory(self.section)
Пример #9
0
    def get_config_dir(self):
        """
        Gives the directory where the configuration file is.

        :return: Directory of the config file.
        """
        return get_config_directory(self.section)
Пример #10
0
 def test_bear_dirs(self):
     section = Section("section", None)
     empty_bear_dirs_len = len(section.bear_dirs())
     section.append(Setting("bear_dirs", "test1, test2 (1)"))
     self.assertEqual(len(section.bear_dirs()), empty_bear_dirs_len + 2)
     # Verify if bear directories are properly escaped
     root = get_config_directory(section)
     path = os.path.join(glob_escape(root), glob_escape("test2 (1)"), "**")
     self.assertIn(path, section.bear_dirs())
Пример #11
0
 def test_bear_dirs(self):
     section = Section('section', None)
     empty_bear_dirs_len = len(section.bear_dirs())
     section.append(Setting('bear_dirs', 'test1, test2 (1)'))
     self.assertEqual(len(section.bear_dirs()), empty_bear_dirs_len + 2)
     # Verify if bear directories are properly escaped
     root = get_config_directory(section)
     path = os.path.join(glob_escape(root), glob_escape('test2 (1)'), '**')
     self.assertIn(path, section.bear_dirs())
Пример #12
0
 def test_bear_dirs(self):
     section = Section('section', None)
     empty_bear_dirs_len = len(section.bear_dirs())
     section.append(Setting('bear_dirs', 'test1, test2 (1)'))
     self.assertEqual(len(section.bear_dirs()), empty_bear_dirs_len + 2)
     # Verify if bear directories are properly escaped
     root = get_config_directory(section)
     path = os.path.join(glob_escape(root), glob_escape('test2 (1)'), '**')
     self.assertIn(path, section.bear_dirs())
Пример #13
0
 def test_bear_dirs(self):
     section = Section("section", None)
     empty_bear_dirs_len = len(section.bear_dirs())
     section.append(Setting("bear_dirs", "test1, test2 (1)"))
     self.assertEqual(len(section.bear_dirs()), empty_bear_dirs_len + 2)
     # Verify if bear directories are properly escaped
     root = get_config_directory(section)
     path = os.path.join(glob_escape(root), glob_escape("test2 (1)"), "**")
     self.assertIn(path, section.bear_dirs())
Пример #14
0
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit("A shortlog that is too long is not good for history")
     os.chdir(no_git_dir)
     # When section doesn't have a config setting
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], "git:")
     # when section does have a config setting
     self.section.append(Setting("config", re.escape(self.gitdir)))
     self.assertEqual(self.run_uut(),
                      ["Shortlog of HEAD commit is too long."])
     self.assertEqual(get_config_directory(self.section), self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)
Пример #15
0
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit("A shortlog that is too long is not good for history")
     os.chdir(no_git_dir)
     # When section doesn't have a config setting
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], "git:")
     # when section does have a config setting
     self.section.append(Setting("config", re.escape(self.gitdir)))
     self.assertEqual(self.run_uut(),
                      ["Shortlog of HEAD commit is too long."])
     self.assertEqual(get_config_directory(self.section),
                      self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)
Пример #16
0
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit("Add a very long shortlog for a bad project history.")
     os.chdir(no_git_dir)
     # When section doesn't have a project_dir
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], "git:")
     # when section does have a project_dir
     self.section.append(Setting("project_dir", escape(self.gitdir, '\\')))
     self.assertEqual(self.run_uut(),
                      ["Shortlog of HEAD commit is 1 character(s) longer "
                       "than the limit (51 > 50)."])
     self.assertEqual(get_config_directory(self.section),
                      self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)
Пример #17
0
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit("Add a very long shortlog for a bad project history.")
     os.chdir(no_git_dir)
     # When section doesn't have a project_dir
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], "git:")
     # when section does have a project_dir
     self.section.append(Setting("project_dir", escape(self.gitdir, '\\')))
     self.assertEqual(self.run_uut(),
                      ["Shortlog of HEAD commit is 1 character(s) longer "
                       "than the limit (51 > 50)."])
     self.assertEqual(get_config_directory(self.section),
                      self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit('Add a very long shortlog for a bad project history.')
     os.chdir(no_git_dir)
     # When section doesn't have a project_dir
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], 'git:')
     # when section does have a project_dir
     self.section.append(Setting('project_dir', escape(self.gitdir, '\\')))
     self.assertEqual(self.run_uut(),
                      ['Shortlog of the HEAD commit contains 51 '
                       'character(s). This is 1 character(s) longer than '
                       'the limit (51 > 50).'])
     self.assertEqual(get_config_directory(self.section),
                      self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)
Пример #19
0
 def test_different_path(self):
     no_git_dir = mkdtemp()
     self.git_commit('Add a very long shortlog for a bad project history.')
     os.chdir(no_git_dir)
     # When section doesn't have a project_dir
     self.assertEqual(self.run_uut(), [])
     git_error = self.msg_queue.get().message
     self.assertEqual(git_error[:4], 'git:')
     # when section does have a project_dir
     self.section.append(Setting('project_dir', escape(self.gitdir, '\\')))
     self.assertEqual(self.run_uut(), [
         'Shortlog of the HEAD commit contains 51 '
         'character(s). This is 1 character(s) longer than '
         'the limit (51 > 50).'
     ])
     self.assertEqual(get_config_directory(self.section), self.gitdir)
     os.chdir(self.gitdir)
     os.rmdir(no_git_dir)