-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstage_fpids.py
executable file
·91 lines (70 loc) · 3.17 KB
/
stage_fpids.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
import os, filecmp, shutil, time
import sporklib
EPUB_DIR = "/home/content/uploaded/epubs"
PDF_DIR = "/home/content/uploaded/pdfs"
COVER_DIR = "/home/content/uploaded/covers"
XML_DIR = "/home/content/uploaded/xmls"
STAGE_DIR = "/home/content/uploaded/Cowbird"
ignore_dirs = []
ignore_dirs.append('/home/content/uploaded/epubs/error')
#ignore_dirs.append('/home/content/uploaded/epubs/error/accept')
ignore_dirs.append('/home/content/uploaded/epubs/error/reject')
path_list = []
for dirpath, dirnames, filenames in os.walk(EPUB_DIR):
if dirpath not in ignore_dirs:
for files in filenames:
path_list.append(os.path.join(dirpath,files))
for dirpath, dirnames, filenames in os.walk(PDF_DIR):
if dirpath not in ignore_dirs:
for files in filenames:
path_list.append(os.path.join(dirpath,files))
for dirpath, dirnames, filenames in os.walk(COVER_DIR):
if dirpath not in ignore_dirs:
for files in filenames:
path_list.append(os.path.join(dirpath,files))
for dirpath, dirnames, filenames in os.walk(XML_DIR):
if dirpath not in ignore_dirs:
for files in filenames:
path_list.append(os.path.join(dirpath,files))
################################
query_fpid_list = sporklib.get_query_list()
################################
counter = 0
for item in query_fpid_list:
files = [x for x in path_list if item in x]
counter += 1
sub_counter = 0
has_epub = False
has_pdf = False
has_xml = False
has_cover = False
for file1 in files:
if file1.endswith('.epub'):
has_epub = True
elif file1.endswith('.pdf'):
has_pdf = True
elif file1.endswith('.xml'):
has_xml = True
elif file1.endswith('.jpg'):
has_cover = True
if not has_epub:
print "--------------------------------------------> Missing Epub for {}".format(item)
if not has_pdf:
print "--------------------------------------------> Missing Pdf for {}".format(item)
if not has_xml:
print "--------------------------------------------> Missing Metadata for {}".format(item)
if not has_cover:
print "--------------------------------------------> Missing Cover for {}".format(item)
if has_epub and has_xml:
for file1 in files:
sub_counter += 1
file2 = os.path.join(STAGE_DIR,os.path.split(file1)[1])
if os.path.exists(file2):
print "Already have " + file2
else:
# print "{}.{} Copying {} to {}".format(counter,sub_counter,file1,file2)
# shutil.copy(file1,file2)
print "{}.{} linking {} to {}".format(counter,sub_counter,file1,file2)
os.chdir(STAGE_DIR)
os.symlink(file1,file2)