Compare commits
4 Commits
main
...
python/dev
Author | SHA1 | Date |
---|---|---|
suyono17 | 1fdf5f2e14 | |
Suyono | 8790e0c8b0 | |
Suyono | 70d2200706 | |
Suyono | 5d10ec5011 |
|
@ -0,0 +1 @@
|
||||||
|
/venv/*
|
|
@ -0,0 +1,8 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (tarroot)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/tarroot.iml" filepath="$PROJECT_DIR$/.idea/tarroot.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="Python 3.10 (tarroot)" jdkType="Python SDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -0,0 +1,83 @@
|
||||||
|
# This is a sample Python script.
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
|
||||||
|
class TarRoot:
|
||||||
|
def __init__(self, arguments):
|
||||||
|
self.debug = arguments.debug
|
||||||
|
self.target_dir = arguments.target_dir
|
||||||
|
self.tar = tarfile.open(arguments.target_tar, "w:gz", compresslevel=6)
|
||||||
|
|
||||||
|
def debug_print(self, *arguments):
|
||||||
|
if self.debug:
|
||||||
|
output = ""
|
||||||
|
for arg in arguments:
|
||||||
|
output += repr(arg)
|
||||||
|
print("DEBUG: " + output)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
start_dir = os.getcwd()
|
||||||
|
self.debug_print("entering target dir: ", self.target_dir)
|
||||||
|
os.chdir(self.target_dir)
|
||||||
|
self._run('.')
|
||||||
|
self.debug_print("returning to original dir: ", start_dir)
|
||||||
|
os.chdir(start_dir)
|
||||||
|
self.tar.close()
|
||||||
|
|
||||||
|
def _append_symlink(self, entry, *parent):
|
||||||
|
path = entry.name
|
||||||
|
if len(parent) > 0:
|
||||||
|
path = parent[0] + os.sep + path
|
||||||
|
self.debug_print("adding symlink {0}".format(path))
|
||||||
|
ti = self.tar.gettarinfo(name=path)
|
||||||
|
self.tar.addfile(ti)
|
||||||
|
|
||||||
|
def _append_dir(self, entry, *parent):
|
||||||
|
path = entry.name
|
||||||
|
if len(parent) > 0:
|
||||||
|
path = parent[0] + os.sep + path
|
||||||
|
self.debug_print("adding directory {0}".format(path))
|
||||||
|
ti = self.tar.gettarinfo(name=path)
|
||||||
|
# self.debug_print("directory attribute", ti)
|
||||||
|
self.tar.addfile(tarinfo=ti)
|
||||||
|
|
||||||
|
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 = []
|
||||||
|
with os.scandir(running_dir) as it:
|
||||||
|
for entry in it:
|
||||||
|
if entry.is_symlink():
|
||||||
|
self.debug_print("appending symlink ", entry)
|
||||||
|
# symlinks.append(entry)
|
||||||
|
self._append_symlink(entry, running_dir) if running_dir != "." else self._append_symlink(entry)
|
||||||
|
elif entry.is_dir():
|
||||||
|
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, running_dir) if running_dir != "." else self._append_file(entry)
|
||||||
|
|
||||||
|
|
||||||
|
# Press the green button in the gutter to run the script.
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--debug", help="debug flag", action="store_true")
|
||||||
|
parser.add_argument("target_dir")
|
||||||
|
parser.add_argument("target_tar")
|
||||||
|
args = parser.parse_args()
|
||||||
|
tr = TarRoot(args)
|
||||||
|
tr.run()
|
Loading…
Reference in New Issue