Add python script to map files to directory structure, use compression for package
This commit is contained in:
		
							
								
								
									
										121
									
								
								fs_dump/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								fs_dump/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,121 @@
 | 
			
		||||
# Created by https://www.toptal.com/developers/gitignore/api/pycharm
 | 
			
		||||
# Edit at https://www.toptal.com/developers/gitignore?templates=pycharm
 | 
			
		||||
 | 
			
		||||
### PyCharm ###
 | 
			
		||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
 | 
			
		||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
 | 
			
		||||
 | 
			
		||||
# User-specific stuff
 | 
			
		||||
.idea/**/workspace.xml
 | 
			
		||||
.idea/**/tasks.xml
 | 
			
		||||
.idea/**/usage.statistics.xml
 | 
			
		||||
.idea/**/dictionaries
 | 
			
		||||
.idea/**/shelf
 | 
			
		||||
 | 
			
		||||
# AWS User-specific
 | 
			
		||||
.idea/**/aws.xml
 | 
			
		||||
 | 
			
		||||
# Generated files
 | 
			
		||||
.idea/**/contentModel.xml
 | 
			
		||||
 | 
			
		||||
# Sensitive or high-churn files
 | 
			
		||||
.idea/**/dataSources/
 | 
			
		||||
.idea/**/dataSources.ids
 | 
			
		||||
.idea/**/dataSources.local.xml
 | 
			
		||||
.idea/**/sqlDataSources.xml
 | 
			
		||||
.idea/**/dynamic.xml
 | 
			
		||||
.idea/**/uiDesigner.xml
 | 
			
		||||
.idea/**/dbnavigator.xml
 | 
			
		||||
 | 
			
		||||
# Gradle
 | 
			
		||||
.idea/**/gradle.xml
 | 
			
		||||
.idea/**/libraries
 | 
			
		||||
 | 
			
		||||
# Gradle and Maven with auto-import
 | 
			
		||||
# When using Gradle or Maven with auto-import, you should exclude module files,
 | 
			
		||||
# since they will be recreated, and may cause churn.  Uncomment if using
 | 
			
		||||
# auto-import.
 | 
			
		||||
# .idea/artifacts
 | 
			
		||||
# .idea/compiler.xml
 | 
			
		||||
# .idea/jarRepositories.xml
 | 
			
		||||
# .idea/modules.xml
 | 
			
		||||
# .idea/*.iml
 | 
			
		||||
# .idea/modules
 | 
			
		||||
# *.iml
 | 
			
		||||
# *.ipr
 | 
			
		||||
 | 
			
		||||
# CMake
 | 
			
		||||
cmake-build-*/
 | 
			
		||||
 | 
			
		||||
# Mongo Explorer plugin
 | 
			
		||||
.idea/**/mongoSettings.xml
 | 
			
		||||
 | 
			
		||||
# File-based project format
 | 
			
		||||
*.iws
 | 
			
		||||
 | 
			
		||||
# IntelliJ
 | 
			
		||||
out/
 | 
			
		||||
 | 
			
		||||
# mpeltonen/sbt-idea plugin
 | 
			
		||||
.idea_modules/
 | 
			
		||||
 | 
			
		||||
# JIRA plugin
 | 
			
		||||
atlassian-ide-plugin.xml
 | 
			
		||||
 | 
			
		||||
# Cursive Clojure plugin
 | 
			
		||||
.idea/replstate.xml
 | 
			
		||||
 | 
			
		||||
# SonarLint plugin
 | 
			
		||||
.idea/sonarlint/
 | 
			
		||||
 | 
			
		||||
# Crashlytics plugin (for Android Studio and IntelliJ)
 | 
			
		||||
com_crashlytics_export_strings.xml
 | 
			
		||||
crashlytics.properties
 | 
			
		||||
crashlytics-build.properties
 | 
			
		||||
fabric.properties
 | 
			
		||||
 | 
			
		||||
# Editor-based Rest Client
 | 
			
		||||
.idea/httpRequests
 | 
			
		||||
 | 
			
		||||
# Android studio 3.1+ serialized cache file
 | 
			
		||||
.idea/caches/build_file_checksums.ser
 | 
			
		||||
 | 
			
		||||
### PyCharm Patch ###
 | 
			
		||||
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
 | 
			
		||||
 | 
			
		||||
# *.iml
 | 
			
		||||
# modules.xml
 | 
			
		||||
# .idea/misc.xml
 | 
			
		||||
# *.ipr
 | 
			
		||||
 | 
			
		||||
# Sonarlint plugin
 | 
			
		||||
# https://plugins.jetbrains.com/plugin/7973-sonarlint
 | 
			
		||||
.idea/**/sonarlint/
 | 
			
		||||
 | 
			
		||||
# SonarQube Plugin
 | 
			
		||||
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
 | 
			
		||||
.idea/**/sonarIssues.xml
 | 
			
		||||
 | 
			
		||||
# Markdown Navigator plugin
 | 
			
		||||
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
 | 
			
		||||
.idea/**/markdown-navigator.xml
 | 
			
		||||
.idea/**/markdown-navigator-enh.xml
 | 
			
		||||
.idea/**/markdown-navigator/
 | 
			
		||||
 | 
			
		||||
# Cache file creation bug
 | 
			
		||||
# See https://youtrack.jetbrains.com/issue/JBR-2257
 | 
			
		||||
.idea/$CACHE_FILE$
 | 
			
		||||
 | 
			
		||||
# CodeStream plugin
 | 
			
		||||
# https://plugins.jetbrains.com/plugin/12206-codestream
 | 
			
		||||
.idea/codestream.xml
 | 
			
		||||
 | 
			
		||||
# Azure Toolkit for IntelliJ plugin
 | 
			
		||||
# https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij
 | 
			
		||||
.idea/**/azureSettings.xml
 | 
			
		||||
 | 
			
		||||
# End of https://www.toptal.com/developers/gitignore/api/pycharm
 | 
			
		||||
 | 
			
		||||
dump
 | 
			
		||||
files
 | 
			
		||||
sqlite.db
 | 
			
		||||
							
								
								
									
										8
									
								
								fs_dump/.idea/fs_dump.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								fs_dump/.idea/fs_dump.iml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<module type="PYTHON_MODULE" version="4">
 | 
			
		||||
  <component name="NewModuleRootManager">
 | 
			
		||||
    <content url="file://$MODULE_DIR$" />
 | 
			
		||||
    <orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
 | 
			
		||||
    <orderEntry type="sourceFolder" forTests="false" />
 | 
			
		||||
  </component>
 | 
			
		||||
</module>
 | 
			
		||||
							
								
								
									
										6
									
								
								fs_dump/.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								fs_dump/.idea/inspectionProfiles/profiles_settings.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<component name="InspectionProjectProfileManager">
 | 
			
		||||
  <settings>
 | 
			
		||||
    <option name="USE_PROJECT_PROFILE" value="false" />
 | 
			
		||||
    <version value="1.0" />
 | 
			
		||||
  </settings>
 | 
			
		||||
</component>
 | 
			
		||||
							
								
								
									
										4
									
								
								fs_dump/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								fs_dump/.idea/misc.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -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" project-jdk-type="Python SDK" />
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										8
									
								
								fs_dump/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								fs_dump/.idea/modules.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ProjectModuleManager">
 | 
			
		||||
    <modules>
 | 
			
		||||
      <module fileurl="file://$PROJECT_DIR$/.idea/fs_dump.iml" filepath="$PROJECT_DIR$/.idea/fs_dump.iml" />
 | 
			
		||||
    </modules>
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
							
								
								
									
										6
									
								
								fs_dump/.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								fs_dump/.idea/vcs.xml
									
									
									
										generated
									
									
									
										Normal file
									
								
							@@ -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>
 | 
			
		||||
							
								
								
									
										66
									
								
								fs_dump/create_disks.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								fs_dump/create_disks.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,66 @@
 | 
			
		||||
from peewee import SqliteDatabase, Model, AutoField, IntegerField, TextField, BlobField
 | 
			
		||||
from pathlib import Path
 | 
			
		||||
import shutil
 | 
			
		||||
 | 
			
		||||
db = SqliteDatabase('sqlite.db')
 | 
			
		||||
dump_path = Path('dump')
 | 
			
		||||
 | 
			
		||||
class User(Model):
 | 
			
		||||
    class Meta:
 | 
			
		||||
        table_name = 'user'
 | 
			
		||||
        database = db
 | 
			
		||||
 | 
			
		||||
    id = AutoField()
 | 
			
		||||
    gitlab = IntegerField()
 | 
			
		||||
    name = TextField()
 | 
			
		||||
    password = TextField()
 | 
			
		||||
    role = IntegerField()
 | 
			
		||||
    root_id = IntegerField()
 | 
			
		||||
    tfa_type = IntegerField()
 | 
			
		||||
    tfa_secret = BlobField()
 | 
			
		||||
    gitlab_at = TextField()
 | 
			
		||||
    gitlab_rt = TextField()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class INode(Model):
 | 
			
		||||
    class Meta:
 | 
			
		||||
        table_name = 'inode'
 | 
			
		||||
        database = db
 | 
			
		||||
 | 
			
		||||
    id = AutoField()
 | 
			
		||||
    is_file = IntegerField()
 | 
			
		||||
    name = TextField()
 | 
			
		||||
    parent_id = IntegerField()
 | 
			
		||||
    owner_id = IntegerField()
 | 
			
		||||
    size = IntegerField()
 | 
			
		||||
    has_preview = IntegerField()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_inode(node: INode, path: Path):
 | 
			
		||||
    new_path: Path = path / node.name
 | 
			
		||||
    if node.is_file == 0:
 | 
			
		||||
        new_path.mkdir()
 | 
			
		||||
        children = INode.select().where(INode.parent_id == node.id)
 | 
			
		||||
        for child in children:
 | 
			
		||||
            parse_inode(child, new_path)
 | 
			
		||||
    else:
 | 
			
		||||
        shutil.copy(f'files/{node.id}', new_path)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def parse_user(user: User):
 | 
			
		||||
    path: Path = dump_path / user.name
 | 
			
		||||
    path.mkdir()
 | 
			
		||||
    root_children = INode.select().where(INode.parent_id == user.root_id)
 | 
			
		||||
    for child in root_children:
 | 
			
		||||
        parse_inode(child, path)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    if dump_path.exists():
 | 
			
		||||
        shutil.rmtree(dump_path)
 | 
			
		||||
    dump_path.mkdir()
 | 
			
		||||
 | 
			
		||||
    db.connect()
 | 
			
		||||
    users = User.select()
 | 
			
		||||
    for user in users:
 | 
			
		||||
        parse_user(user)
 | 
			
		||||
		Reference in New Issue
	
	Block a user