diff --git a/distribusi/distribusi/distribusi.py b/distribusi/distribusi/distribusi.py index 554d80c..8447722 100644 --- a/distribusi/distribusi/distribusi.py +++ b/distribusi/distribusi/distribusi.py @@ -23,8 +23,8 @@ MIME_TYPE = magic.Magic(mime=True) ignore = Ignore() -PATTERN_TAG = re.compile(r"(?P.+?)(?P\#.+)*\.(?P.{1,4}$)") -PATTERN_TAG_FOLDER = re.compile(r"(?P.+?)(?P\#.+)\/(?P.+)") +PATTERN_TAG = re.compile(r"(?P.+?)(?P\#.+)*\.(?P.{1,4}$)") +PATTERN_TAG_FOLDER = re.compile(r"(?P.+?)(?P\#.+)\/(?P.+)") def caption(image): try: @@ -303,6 +303,8 @@ def distribusify(args, directory, freg): # noqa print("Ignore : " + name) elif 'index.html' not in name: full_path = os.path.join(root, name) + #unfold all the symlinks, too + full_path = os.path.realpath(full_path) mime = MIME_TYPE.from_file(full_path) # example: MIME plain/text becomes 'type' plain 'subtype' text type_, subtype = mime.split('/') diff --git a/distribusi/distribusi/fragments.py b/distribusi/distribusi/fragments.py index 6133016..e0b1289 100644 --- a/distribusi/distribusi/fragments.py +++ b/distribusi/distribusi/fragments.py @@ -1,10 +1,25 @@ -# -*- coding: utf-8 -*- -import os +# -*- coding: utf-8 -*- +import os, shutil import platform import json from operator import itemgetter from distribusi.ignore import Ignore +import re +PATTERN_TAG = re.compile(r"(?P.+?)(?P\#.+)*\.(?P.{1,4}$)") +PATTERN_TAG_FOLDER = re.compile(r"(?P.+?)(?P\#.+)\/(?P.+)") + +def cleanfolder(folder): + for filename in os.listdir(folder): + file_path = os.path.join(folder, filename) + try: + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception as e: + print('Failed to delete %s. Reason: %s' % (file_path, e)) + class Fragment: def __init__(self, index, update, directory, artist, file): self.index = index @@ -25,6 +40,16 @@ class Fragments: self.timetable = [] self.ignore = Ignore() + # hash generated folders + # ==> these are only for distribusi rendering / not for indexing. + self.ignore.ignore.append('hash_human') + self.ignore.ignore.append('hash_tech') + self.ignore.ignore.append('hash_environment') + + cleanfolder('./data/hash_human') + cleanfolder('./data/hash_tech') + cleanfolder('./data/hash_environment') + self.index_file = 'index.json' def init_json(self, directory): @@ -99,6 +124,26 @@ class Fragments: if self.ignore.test(arr[2]): pass # ignore 폴더 처리 else: + # tags processing + for name in sorted(files): + m = PATTERN_TAG.search(name) + if m: + file_tags = m.group('tags') + if file_tags is not None: + tags = file_tags.split('#') + for tag in tags: + root2 = os.path.relpath(root, './data') + src_path = os.path.join('../', root2, name) + if tag == '인간': + os.symlink(src_path, './data/hash_human/' + name) + print(src_path, ' ==> ', './data/hash_human/' + name) + elif tag == '기술': + os.symlink(src_path, './data/hash_tech/' + name) + print(src_path, ' ==> ', './data/hash_tech/' + name) + elif tag == '환경': + os.symlink(src_path, './data/hash_environment/' + name) + print(src_path, ' ==> ', './data/hash_environment/' + name) + # 2뎁스까지만 인덱스 함. if arr.__len__() < 4: # files index diff --git a/test_data/.ignore b/test_data/.ignore index ebebabd..64512ed 100644 --- a/test_data/.ignore +++ b/test_data/.ignore @@ -14,9 +14,6 @@ style.css main.js .+.alt events -hash_human -hash_tech -hash_environment 여기에_대해_about_here 어떤_파일을_넣을까 process