67 lines
1.5 KiB
Python
67 lines
1.5 KiB
Python
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)
|