WIP: processed file & directory; next symlinks

This commit is contained in:
Suyono 2022-11-24 14:51:29 +11:00
parent 5d10ec5011
commit 70d2200706
1 changed files with 10 additions and 5 deletions

View File

@ -3,6 +3,7 @@
# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
import stat
import argparse
import os
import tarfile
@ -33,18 +34,23 @@ class TarRoot:
path = entry.name
if len(parent) > 0:
path = parent[0] + os.sep + path
self.debug_print("adding directory {0}".format(path))
ti = tarfile.TarInfo(path)
ti.type = tarfile.DIRTYPE
stat_result = entry.stat(follow_symlinks=False)
ti.mode = stat_result.st_mode
ti.mode = stat.S_IMODE(stat_result.st_mode)
ti.uid = stat_result.st_uid
ti.gid = stat_result.st_gid
ti.mtime = stat_result.st_mtime
self.debug_print("writing tar info ", ti)
self.tar.addfile(ti)
def _append_file(self, entry):
pass
def _append_file(self, entry, *parent):
path = entry.name
if len(parent) > 0:
path = parent[0] + os.sep + path
self.debug_print("adding file {0}".format(path))
self.tar.add(path)
def _run(self, running_dir):
symlinks = []
@ -54,13 +60,12 @@ class TarRoot:
self.debug_print("appending symlink ", entry)
symlinks.append(entry)
elif entry.is_dir():
self.debug_print("appending directory ", entry)
self._append_dir(entry, running_dir) if running_dir != "." else self._append_dir(entry)
self.debug_print("going recursive")
self._run(running_dir + os.sep + entry.name) if running_dir != "." else self._run(entry.name)
else:
self.debug_print("appending file ", entry)
self._append_file(entry)
self._append_file(entry, running_dir) if running_dir != "." else self._append_file(entry)
# Press the green button in the gutter to run the script.