Selaa lähdekoodia

refactor indicator (status) and item processing

process_item was used only for dirs and fifo, replaced it by process_dir and process_fifo,
so the status can be generated there (as it is done for the other item types).
Thomas Waldmann 10 vuotta sitten
vanhempi
sitoutus
6d67379c08
2 muutettua tiedostoa jossa 13 lisäystä ja 10 poistoa
  1. 11 6
      attic/archive.py
  2. 2 4
      attic/archiver.py

+ 11 - 6
attic/archive.py

@@ -365,28 +365,33 @@ class Archive:
         acl_get(path, item, st, self.numeric_owner)
         acl_get(path, item, st, self.numeric_owner)
         return item
         return item
 
 
-    def process_item(self, path, st):
+    def process_dir(self, path, st):
         item = {b'path': make_path_safe(path)}
         item = {b'path': make_path_safe(path)}
         item.update(self.stat_attrs(st, path))
         item.update(self.stat_attrs(st, path))
         self.add_item(item)
         self.add_item(item)
+        return 'd'  # directory
+
+    def process_fifo(self, path, st):
+        item = {b'path': make_path_safe(path)}
+        item.update(self.stat_attrs(st, path))
+        self.add_item(item)
+        return 'f'  # fifo
 
 
     def process_dev(self, path, st):
     def process_dev(self, path, st):
         item = {b'path': make_path_safe(path), b'rdev': st.st_rdev}
         item = {b'path': make_path_safe(path), b'rdev': st.st_rdev}
         item.update(self.stat_attrs(st, path))
         item.update(self.stat_attrs(st, path))
         self.add_item(item)
         self.add_item(item)
         if stat.S_ISCHR(st.st_mode):
         if stat.S_ISCHR(st.st_mode):
-            status = 'c'  # char device
+            return 'c'  # char device
         elif stat.S_ISBLK(st.st_mode):
         elif stat.S_ISBLK(st.st_mode):
-            status = 'b'  # block device
-        return status
+            return 'b'  # block device
 
 
     def process_symlink(self, path, st):
     def process_symlink(self, path, st):
         source = os.readlink(path)
         source = os.readlink(path)
         item = {b'path': make_path_safe(path), b'source': source}
         item = {b'path': make_path_safe(path), b'source': source}
         item.update(self.stat_attrs(st, path))
         item.update(self.stat_attrs(st, path))
         self.add_item(item)
         self.add_item(item)
-        status = 's'  # symlink
-        return status
+        return 's'  # symlink
 
 
     def process_file(self, path, st, cache):
     def process_file(self, path, st, cache):
         status = None
         status = None

+ 2 - 4
attic/archiver.py

@@ -166,8 +166,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         elif stat.S_ISDIR(st.st_mode):
         elif stat.S_ISDIR(st.st_mode):
             if exclude_caches and is_cachedir(path):
             if exclude_caches and is_cachedir(path):
                 return
                 return
-            archive.process_item(path, st)
-            status = 'd'  # directory
+            status = archive.process_dir(path, st)
             try:
             try:
                 entries = os.listdir(path)
                 entries = os.listdir(path)
             except OSError as e:
             except OSError as e:
@@ -179,8 +178,7 @@ Type "Yes I am sure" if you understand this and want to continue.\n""")
         elif stat.S_ISLNK(st.st_mode):
         elif stat.S_ISLNK(st.st_mode):
             status = archive.process_symlink(path, st)
             status = archive.process_symlink(path, st)
         elif stat.S_ISFIFO(st.st_mode):
         elif stat.S_ISFIFO(st.st_mode):
-            archive.process_item(path, st)
-            status = 'f'  # fifo
+            status = archive.process_fifo(path, st)
         elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
         elif stat.S_ISCHR(st.st_mode) or stat.S_ISBLK(st.st_mode):
             status = archive.process_dev(path, st)
             status = archive.process_dev(path, st)
         else:
         else: