コード例 #1
0
 def test_list_snapshots(self):
     res = [s.name for s in snapshots.get_list()]
     dirlist = os.listdir(snapshots.mp)
     expected = [i for i in dirlist if i.startswith(SNAP_PREFIX)]
     expected.remove(u'@apt-snapshot-xxxx-xx-xx_xx:xx:xx-bad-date')
     expected.remove(u'@apt-snapshot-bad-date')
     self.assertItemsEqual(expected, res)
コード例 #2
0
 def delete_older_than(self, timefmt):
     older_than = self._parse_older_than_to_datetime(timefmt)
     res = True
     list_of = snapshots.get_list(older_than=older_than)
     list_of.sort(key = lambda x: x.date, reverse = True)
     for snap in list_of:
         if len(snap.children) < 2 and snap.tag == "":
             res &= self.delete(snap)
     return res
コード例 #3
0
 def test_list_snapshots_older_than(self):
     older_than = datetime.datetime(2013, 8, 3)
     res = snapshots.get_list(older_than=older_than)
     self.assertEqual(len(res), 5)
     for i in res:
         self.assertTrue(i.date < older_than)
     
     older_than = datetime.datetime(2013, 7, 27)
     res = snapshots.get_list(older_than=older_than)
     for i in res:
         self.assertTrue(i.date < older_than)
     self.assertEqual(len(res), 1)
     
     res = snapshots.get_list()
     self.assertEqual(len(res), 16)
     
     older_than = "2013-08-07_18:00:42"
     res = snapshots.get_list(older_than=older_than)
     older_than = datetime.datetime(2013, 8, 7, 18, 0, 42)
     self.assertEqual(len(res), 8)
     for i in res:
         self.assertTrue(i.date < older_than)
コード例 #4
0
 def clean(self, what="apt-cache"):
     snapshot_list = snapshots.get_list()
     for snapshot in snapshot_list:
         path = os.path.join(self.mp, snapshot.name)
         if what == "apt-cache":
             path = os.path.join(path, "var/cache/apt/archives")
             if not os.path.exists(path):
                 continue
             dirlist = os.listdir(path)
             for f in dirlist:
                 fpath = os.path.join(path, f)
                 if f.endswith(".deb") and os.path.lexists(fpath):
                     os.remove(fpath)
コード例 #5
0
ファイル: convert.py プロジェクト: jpeg729/apt-btrfs-snapshot
)
from dpkg_history import DpkgHistory

if __name__ == "__main__":

    if os.getuid() != 0 and len(sys.argv) == 1:
        print(_("Sorry, you need to be root to run this program"))
        sys.exit(1)

    if not supported():
        print(_("Sorry, your system lacks support for the snapshot feature"))
        sys.exit(1)
    
    if len(sys.argv) > 1:
        apt_btrfs = AptBtrfsSnapshot(test_mp = sys.argv[1])
    else:
        apt_btrfs = AptBtrfsSnapshot()
    mountpoint = apt_btrfs.mp
    snaplist = snapshots.get_list()
    snaplist.sort(key = lambda x: x.date)
    
    previous = None
    for snap in snaplist:
        if previous:
            snap.parent = previous
            location = os.path.join(mountpoint, snap.name, "var")
            date = previous.date
            snap.changes = DpkgHistory(var_location=location, since=date)
        previous = snap
    Snapshot("@").parent = previous
コード例 #6
0
    def print(self):
        """ pretty print a view of the tree """
        self.column = 1
        self.orphans = []
        self.junctions = {}
        
        no_children = [Snapshot("@")]
        for snap in snapshots.get_list():
            if len(snap.children) == 0:
                no_children.append(snap)
        to_print = no_children
        to_print.sort(key = self._sort_key)
        
        while True:
            try:
                snapshot = to_print.pop()
            except IndexError:
                break

            junction = self._print_up_to_junction(snapshot)
            to_print.sort(key = self._sort_key)
            
            if junction == None:
                
                # We have reached the end of a disconnected branch
                self.orphans.append(self.column)
                print(self._spacer() + u"×  ")
                        
            elif junction not in self.junctions:
                
                # new junction found
                print(self._spacer() + u"│  ")
                
                self.junctions[junction] = Junction(junction, self.column)
                self.junctions[junction].branches_left_to_print -= 1
                
            else:
                # already seen this junction
                self.junctions[junction].branches_left_to_print -= 1
                self.junctions[junction].columns.append(self.column)
                
                if self.junctions[junction].branches_left_to_print == 0:
                
                    to_print.append(junction)
                    
                    # construct and print branch join up line
                    cols = self.junctions[junction].columns
                    joinup = self._spacer(cols[0]) + u"├──"
                    for i in range(cols[0] + 1, cols[-1]):
                        if i in cols:
                            joinup += u"┴──"
                        else:
                            joinup += u"───"
                    joinup += u"┘"
                    print(joinup)
                    
                    # clean-ups
                    self.column = self.junctions[junction].columns[0] - 1
                    self.orphans = [x for x in self.orphans 
                                          if x <= self.column]
                    del self.junctions[junction]
            
            self.column += 1
コード例 #7
0
 def list_older_than(self, timefmt):
     older_than = self._parse_older_than_to_datetime(timefmt)
     print("Available snapshots older than '%s':" % timefmt)
     print("  \n".join(snapshots.get_list(older_than=older_than)))
     return True
コード例 #8
0
 def list(self):
     # The function name will not clash with reserved keywords. It is only
     # accessible via self.list()
     print("Available snapshots:")
     print("  \n".join(snapshots.get_list()))
     return True