-
Notifications
You must be signed in to change notification settings - Fork 105
/
paths.py
43 lines (35 loc) · 1.45 KB
/
paths.py
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
#! /usr/bin/env python3
# -*- coding:utf-8 -*-
import os
root_dir = os.path.dirname(__file__)
data_dir = os.path.join(root_dir, 'data')
raw_dir = os.path.join(root_dir, 'raw')
save_dir = os.path.join(root_dir, 'save')
sxhy_path = os.path.join(data_dir, 'sxhy_dict.txt')
char_dict_path = os.path.join(data_dir, 'char_dict.txt')
poems_path = os.path.join(data_dir, 'poem.txt')
char2vec_path = os.path.join(data_dir, 'char2vec.npy')
wordrank_path = os.path.join(data_dir, 'wordrank.txt')
plan_data_path = os.path.join(data_dir, 'plan_data.txt')
gen_data_path = os.path.join(data_dir, 'gen_data.txt')
# TODO: configure dependencies in another file.
_dependency_dict = {
poems_path : [char_dict_path],
char2vec_path : [char_dict_path, poems_path],
wordrank_path : [sxhy_path, poems_path],
gen_data_path : [char_dict_path, poems_path, sxhy_path, char2vec_path],
plan_data_path : [char_dict_path, poems_path, sxhy_path, char2vec_path],
}
def check_uptodate(path):
""" Return true iff the file exists and up-to-date with dependencies."""
if not os.path.exists(path):
# File not found.
return False
timestamp = os.path.getmtime(path)
if path in _dependency_dict:
for dependency in _dependency_dict[path]:
if not os.path.exists(dependency) or \
os.path.getmtime(dependency) > timestamp:
# File stale.
return False
return True