This commit is contained in:
Hyunchul Kim 2021-09-15 22:30:17 +09:00
commit 572db4528f
3 changed files with 51 additions and 7 deletions

View file

@ -23,8 +23,8 @@ MIME_TYPE = magic.Magic(mime=True)
ignore = Ignore() ignore = Ignore()
PATTERN_TAG = re.compile(r"(?P<name>.+?)(?P<hashes>\#.+)*\.(?P<ext>.{1,4}$)") PATTERN_TAG = re.compile(r"(?P<name>.+?)(?P<tags>\#.+)*\.(?P<ext>.{1,4}$)")
PATTERN_TAG_FOLDER = re.compile(r"(?P<name>.+?)(?P<hashes>\#.+)\/(?P<file>.+)") PATTERN_TAG_FOLDER = re.compile(r"(?P<name>.+?)(?P<tags>\#.+)\/(?P<file>.+)")
def caption(image): def caption(image):
try: try:
@ -303,6 +303,8 @@ def distribusify(args, directory, freg): # noqa
print("Ignore : " + name) print("Ignore : " + name)
elif 'index.html' not in name: elif 'index.html' not in name:
full_path = os.path.join(root, 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) mime = MIME_TYPE.from_file(full_path)
# example: MIME plain/text becomes 'type' plain 'subtype' text # example: MIME plain/text becomes 'type' plain 'subtype' text
type_, subtype = mime.split('/') type_, subtype = mime.split('/')

View file

@ -1,10 +1,25 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os, shutil
import platform import platform
import json import json
from operator import itemgetter from operator import itemgetter
from distribusi.ignore import Ignore from distribusi.ignore import Ignore
import re
PATTERN_TAG = re.compile(r"(?P<name>.+?)(?P<tags>\#.+)*\.(?P<ext>.{1,4}$)")
PATTERN_TAG_FOLDER = re.compile(r"(?P<name>.+?)(?P<tags>\#.+)\/(?P<file>.+)")
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: class Fragment:
def __init__(self, index, update, directory, artist, file): def __init__(self, index, update, directory, artist, file):
self.index = index self.index = index
@ -25,6 +40,16 @@ class Fragments:
self.timetable = [] self.timetable = []
self.ignore = Ignore() 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' self.index_file = 'index.json'
def init_json(self, directory): def init_json(self, directory):
@ -99,6 +124,26 @@ class Fragments:
if self.ignore.test(arr[2]): if self.ignore.test(arr[2]):
pass # ignore 폴더 처리 pass # ignore 폴더 처리
else: 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뎁스까지만 인덱스 함. # 2뎁스까지만 인덱스 함.
if arr.__len__() < 4: if arr.__len__() < 4:
# files index # files index

View file

@ -14,9 +14,6 @@ style.css
main.js main.js
.+.alt .+.alt
events events
hash_human
hash_tech
hash_environment
여기에_대해_about_here 여기에_대해_about_here
어떤_파일을_넣을까 어떤_파일을_넣을까
process process