From 70d2200706264c90e58e3b8b43748f677a05f73a Mon Sep 17 00:00:00 2001 From: Suyono Date: Thu, 24 Nov 2022 14:51:29 +1100 Subject: [PATCH] WIP: processed file & directory; next symlinks --- tarroot.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tarroot.py b/tarroot.py index 7304bb0..52e5c36 100644 --- a/tarroot.py +++ b/tarroot.py @@ -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.