WIP: processed file & directory; next symlinks
This commit is contained in:
parent
5d10ec5011
commit
70d2200706
15
tarroot.py
15
tarroot.py
|
@ -3,6 +3,7 @@
|
||||||
# Press ⌃R to execute it or replace it with your code.
|
# Press ⌃R to execute it or replace it with your code.
|
||||||
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
|
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
|
||||||
|
|
||||||
|
import stat
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import tarfile
|
import tarfile
|
||||||
|
@ -33,18 +34,23 @@ class TarRoot:
|
||||||
path = entry.name
|
path = entry.name
|
||||||
if len(parent) > 0:
|
if len(parent) > 0:
|
||||||
path = parent[0] + os.sep + path
|
path = parent[0] + os.sep + path
|
||||||
|
self.debug_print("adding directory {0}".format(path))
|
||||||
ti = tarfile.TarInfo(path)
|
ti = tarfile.TarInfo(path)
|
||||||
ti.type = tarfile.DIRTYPE
|
ti.type = tarfile.DIRTYPE
|
||||||
stat_result = entry.stat(follow_symlinks=False)
|
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.uid = stat_result.st_uid
|
||||||
ti.gid = stat_result.st_gid
|
ti.gid = stat_result.st_gid
|
||||||
ti.mtime = stat_result.st_mtime
|
ti.mtime = stat_result.st_mtime
|
||||||
self.debug_print("writing tar info ", ti)
|
self.debug_print("writing tar info ", ti)
|
||||||
self.tar.addfile(ti)
|
self.tar.addfile(ti)
|
||||||
|
|
||||||
def _append_file(self, entry):
|
def _append_file(self, entry, *parent):
|
||||||
pass
|
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):
|
def _run(self, running_dir):
|
||||||
symlinks = []
|
symlinks = []
|
||||||
|
@ -54,13 +60,12 @@ class TarRoot:
|
||||||
self.debug_print("appending symlink ", entry)
|
self.debug_print("appending symlink ", entry)
|
||||||
symlinks.append(entry)
|
symlinks.append(entry)
|
||||||
elif entry.is_dir():
|
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._append_dir(entry, running_dir) if running_dir != "." else self._append_dir(entry)
|
||||||
self.debug_print("going recursive")
|
self.debug_print("going recursive")
|
||||||
self._run(running_dir + os.sep + entry.name) if running_dir != "." else self._run(entry.name)
|
self._run(running_dir + os.sep + entry.name) if running_dir != "." else self._run(entry.name)
|
||||||
else:
|
else:
|
||||||
self.debug_print("appending file ", entry)
|
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.
|
# Press the green button in the gutter to run the script.
|
||||||
|
|
Loading…
Reference in New Issue