Пример #1
0
class TestHistory(unittest.TestCase):
    def setUp(self):
        self.history = History()
        self.history.path = PATH

    def test_find_revision(self):
        times = [
            '2011-08-01 21:17:22 CDT',
            '2011-08-01 22:38:37 CDT',
            '2011-08-01 23:05:07 CDT',
        ]
        for dt, res in [
            ('2011-08-01 21:17:21 CDT', 0),
            ('2011-08-01 21:17:22 CDT', 0),
            ('2011-08-01 21:17:23 CDT', 0),
            ('2011-08-01 22:38:36 CDT', 0),
            ('2011-08-01 22:38:37 CDT', 1),
            ('2011-08-01 22:38:38 CDT', 1),
            ('2011-08-01 23:05:06 CDT', 1),
            ('2011-08-01 23:05:07 CDT', 2),
            ('2011-08-01 23:05:08 CDT', 2),
            ]:
            self.assertEqual(self.history.find_revision(times, dt), res)

    def test_get_state(self):
        self.assertEqual(self.history.get_state(0),
                         set(['appinst-2.1.0-1.egg',
                              'basemap-1.0.1-1.egg',
                              'biopython-1.57-2.egg']))
        self.assertEqual(self.history.get_state(),
                         set(['basemap-1.0.2-1.egg',
                              'biopython-1.57-2.egg',
                              'numpy-1.7.0-1.egg']))
Пример #2
0
class TestHistory(unittest.TestCase):

    def setUp(self):
        self.history = History('<dummy prefix>')
        self.history._log_path = PATH

    def test_get_state(self):
        self.assertEqual(self.history.get_state(0),
                         set(['appinst-2.1.0-1.egg',
                              'basemap-1.0.1-1.egg',
                              'biopython-1.57-2.egg']))
        self.assertEqual(self.history.get_state(),
                         set(['basemap-1.0.2-1.egg',
                              'biopython-1.57-2.egg',
                              'numpy-1.7.0-1.egg']))
Пример #3
0
    def revert_actions(self, arg):
        """
        Calculate the actions necessary to revert to a given state, the
        argument may be one of:
          * complete set of eggs, i.e. a set of egg file names
          * revision number (negative numbers allowed)
        """
        h = History(self.top_prefix)
        h.update()
        if isinstance(arg, set):
            state = arg
        else:
            try:
                rev = int(arg)
            except (TypeError, ValueError):
                raise EnpkgError("Invalid argument: integer expected, "
                                 "got: {0!r}".format(arg))
            try:
                state = h.get_state(rev)
            except IndexError:
                raise EnpkgError("Error: no such revision: %r" % arg)

        curr = h.get_state()
        if state == curr:
            return []

        res = []
        for egg in curr - state:
            if egg.startswith('enstaller'):
                continue
            res.append(('remove', egg))

        for egg in state - curr:
            if egg.startswith('enstaller'):
                continue
            if not isfile(join(self._downloader.cache_directory, egg)):
                eggname, version = egg_name_to_name_version(egg)
                try:
                    self._remote_repository.find_package(eggname, version)
                    res.append(('fetch_0', egg))
                except NoSuchPackage:
                    raise EnpkgError("cannot revert -- missing %r" % egg)
            res.append(('install', egg))
        return res
Пример #4
0
 def setUp(self):
     self.history = History('<dummy prefix>')
     self.history._log_path = PATH
     self.package_sets = [
         set([
             'appinst-2.1.0-1.egg', 'basemap-1.0.1-1.egg',
             'biopython-1.57-2.egg'
         ]),
         set([
             'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg',
             'numpy-1.6.1-2.egg'
         ]),
         set([
             'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg',
             'numpy-1.7.0-1.egg'
         ])
     ]
     # Write the history file
     self.history._write_egg_names(self.package_sets[0])
     for i, state in enumerate(self.package_sets[:-1]):
         self.history._write_changes(state, self.package_sets[i + 1])
Пример #5
0
 def setUp(self):
     self.history = History("<dummy prefix>")
     self.history._log_path = PATH
     self.package_sets = [
         set(["appinst-2.1.0-1.egg", "basemap-1.0.1-1.egg", "biopython-1.57-2.egg"]),
         set(["basemap-1.0.2-1.egg", "biopython-1.57-2.egg", "numpy-1.6.1-2.egg"]),
         set(["basemap-1.0.2-1.egg", "biopython-1.57-2.egg", "numpy-1.7.0-1.egg"]),
     ]
     # Write the history file
     self.history._write_egg_names(self.package_sets[0])
     for i, state in enumerate(self.package_sets[:-1]):
         self.history._write_changes(state, self.package_sets[i + 1])
Пример #6
0
    def revert_actions(self, arg):
        """
        Calculate the actions necessary to revert to a given state, the
        argument may be one of:
          * complete set of eggs, i.e. a set of egg file names
          * revision number (negative numbers allowed)
        """
        h = History(self.top_prefix)
        h.update()
        if isinstance(arg, set):
            state = arg
        else:
            try:
                rev = int(arg)
            except (TypeError, ValueError):
                raise EnpkgError("Invalid argument: integer expected, "
                                 "got: {0!r}".format(arg))
            try:
                state = h.get_state(rev)
            except IndexError:
                raise EnpkgError("Error: no such revision: %r" % arg)

        curr = h.get_state()
        if state == curr:
            return []

        res = []
        for egg in curr - state:
            if egg.startswith('enstaller'):
                continue
            res.append(('remove', egg))

        for egg in state - curr:
            if egg.startswith('enstaller'):
                continue
            if not isfile(join(self._downloader.cache_directory, egg)):
                eggname, version = egg_name_to_name_version(egg)
                try:
                    self._remote_repository.find_package(eggname, version)
                    res.append(('fetch_0', egg))
                except NoSuchPackage:
                    raise EnpkgError("cannot revert -- missing %r" % egg)
            res.append(('install', egg))
        return res
Пример #7
0
class TestHistory(unittest.TestCase):
    def setUp(self):
        self.history = History('<dummy prefix>')
        self.history._log_path = PATH
        self.package_sets = [
            set([
                'appinst-2.1.0-1.egg', 'basemap-1.0.1-1.egg',
                'biopython-1.57-2.egg'
            ]),
            set([
                'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg',
                'numpy-1.6.1-2.egg'
            ]),
            set([
                'basemap-1.0.2-1.egg', 'biopython-1.57-2.egg',
                'numpy-1.7.0-1.egg'
            ])
        ]
        # Write the history file
        self.history._write_egg_names(self.package_sets[0])
        for i, state in enumerate(self.package_sets[:-1]):
            self.history._write_changes(state, self.package_sets[i + 1])

    def tearDown(self):
        if isfile(self.history._log_path):
            unlink(self.history._log_path)

    def test_get_state(self):
        self.assertEqual(self.history.get_state(0), self.package_sets[0])
        self.assertEqual(self.history.get_state(), self.package_sets[-1])

    def test_parse(self):
        package_edits = [packages for (date, packages) in self.history.parse()]
        self.assertEqual(self.package_sets[0], package_edits[0])
        self.assertEqual(
            package_changes(self.package_sets[0], self.package_sets[1]),
            package_edits[1])
        self.history.print_log()

        # When history file is not present
        unlink(self.history._log_path)
        self.assertEqual(self.history.parse(), [])
        self.history.print_log()

    def test_update(self):
        self.history.update()
        self.assertEqual(self.history.get_state(), set())
        self.assertEqual(self.history.parse()[-1][1],
                         package_changes(self.package_sets[-1], set()))
Пример #8
0
def print_history(prefix):
    h = History(prefix)
    h.update()
    h.print_log()
Пример #9
0
 def setUp(self):
     self.history = History('<dummy prefix>')
     self.history._log_path = PATH
Пример #10
0
def print_history(prefix):
    h = History(prefix)
    h.update()
    h.print_log()
Пример #11
0
 def setUp(self):
     self.history = History()
     self.history.path = PATH
Пример #12
0
class TestHistory(unittest.TestCase):

    def setUp(self):
        self.history = History('<dummy prefix>')
        self.history._log_path = PATH
        self.package_sets = [set(['appinst-2.1.0-1.egg',
                                  'basemap-1.0.1-1.egg',
                                  'biopython-1.57-2.egg']),

                             set(['basemap-1.0.2-1.egg',
                                  'biopython-1.57-2.egg',
                                  'numpy-1.6.1-2.egg']),

                             set(['basemap-1.0.2-1.egg',
                                  'biopython-1.57-2.egg',
                                  'numpy-1.7.0-1.egg'])]
        # Write the history file
        self.history._write_egg_names(self.package_sets[0])
        for i, state in enumerate(self.package_sets[:-1]):
            self.history._write_changes(state, self.package_sets[i+1])

    def tearDown(self):
        if isfile(self.history._log_path):
            unlink(self.history._log_path)

    def test_get_state(self):
        self.assertEqual(self.history.get_state(0), self.package_sets[0])
        self.assertEqual(self.history.get_state(), self.package_sets[-1])

    def test_parse(self):
        package_edits = [packages for (date, packages) in self.history.parse()]
        self.assertEqual(self.package_sets[0], package_edits[0])
        self.assertEqual(package_changes(self.package_sets[0],
                                         self.package_sets[1]),
                         package_edits[1])
        self.history.print_log()

        # When history file is not present
        unlink(self.history._log_path)
        self.assertEqual(self.history.parse(), [])
        self.history.print_log()

    def test_update(self):
        self.history.update()
        self.assertEqual(self.history.get_state(), set())
        self.assertEqual(self.history.parse()[-1][1],
                         package_changes(self.package_sets[-1], set()))
Пример #13
0
 def get_history(self):
     """
     return a history (h) object with this Enpkg instance prefix.
     """
     # FIXME: only used by canopy
     return History(self.top_prefix)
Пример #14
0
 def __iter__(self):
     with History(self._top_prefix):
         for action in self._actions:
             logger.info('\t' + str(action))
             yield self._action_factory(action)