Spaces:
Running
Running
File size: 1,653 Bytes
a0d1776 9d9ac18 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import hashlib
import os, shutil
import datetime
from utils.tex_processing import replace_title
def hash_name(input_dict):
'''
input_dict= {"title": title, "description": description}
For same input_dict, it should return the same value.
'''
name = str(input_dict)
name = name.lower()
md5 = hashlib.md5()
md5.update(name.encode('utf-8'))
hashed_string = md5.hexdigest()
return hashed_string
def make_archive(source, destination):
base = os.path.basename(destination)
name = base.split('.')[0]
format = base.split('.')[1]
archive_from = os.path.dirname(source)
archive_to = os.path.basename(source.strip(os.sep))
shutil.make_archive(name, format, archive_from, archive_to)
shutil.move('%s.%s'%(name,format), destination)
return destination
def copy_templates(template, title):
# Create a copy in the outputs folder.
# 1. create a folder "outputs_%Y%m%d_%H%M%S" (destination_folder)
# 2. copy all contents in "latex_templates/{template}" to that folder
# 3. return (bibtex_path, destination_folder)
now = datetime.datetime.now()
target_name = now.strftime("outputs_%Y%m%d_%H%M%S")
source_folder = f"latex_templates/{template}"
destination_folder = f"outputs/{target_name}"
shutil.copytree(source_folder, destination_folder)
bibtex_path = os.path.join(destination_folder, "ref.bib")
# bibtex_path = destination_folder + "/ref.bib"
replace_title(destination_folder, title)
return bibtex_path, destination_folder
def list_folders(path):
return [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))]
|