-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathextract.py
122 lines (95 loc) · 3.23 KB
/
extract.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import sys
import os
import argparse
import shutil
from os.path import join as pjoin
from xml.etree import ElementTree
from collections import namedtuple
from pprint import pprint
from distutils.dir_util import mkpath
class AdobeCCFontExtractor:
pass
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as e:
if e.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
# global configuration object
class Config:
path_prefix = ''
font_dir = ''
manifest = ''
install_path = ''
# font data object
FontData = namedtuple('FontData', 'id name weight')
def get_font_metadata(manifest_path):
tree = ElementTree.parse(manifest_path)
# find the <fonts> element containing the list of fonts
fonts_subtree = tree.getroot().find('fonts')
fonts = []
for font_elem in fonts_subtree.findall('font'):
props = font_elem.find('properties')
f_id = font_elem.find('id').text
f_name = props.find('familyName').text
f_weight = props.find('variationName').text
font = FontData(id=f_id, name=f_name, weight=f_weight)
fonts.append(font)
return fonts
# install the fonts on the system per the --install flag
def install_fonts(fonts):
pass
# extract the fonts to location
# folder structure:
# location/
# Font1/
# Font1 - Variation1.otf
# Font1 - Variation2.otf
def extract_fonts(fonts, font_dir, location):
# make dirs to location if they don't exist
mkpath(location)
for font in fonts:
src = pjoin(font_dir, str(font.id))
filename = font.name + ' - ' + font.weight
dest = pjoin(location, filename)
shutil.copy(src, dest)
def sync_all_fonts():
''' Go to the Adobe CC website and sync EVERY font '''
pass
def platform_setup():
'''Set up paths for MacOS or Windows'''
c = Config()
if sys.platform == 'win32': # Windows
c.path_prefix = \
os.path.expandvars(r'%HOME%\AppData\Roaming\Adobe\CoreSync\plugins\livetype')
c.font_dir = pjoin(c.path_prefix, 'r')
c.manifest = pjoin(c.path_prefix, r'c\entitlements.xml')
else: # MacOS
c.path_prefix = \
os.path.expandvars(r'$HOME/Library/Application Support/Adobe/CoreSync/plugins/livetype')
c.font_dir = os.path.join(c.path_prefix, '.r')
c.manifest = os.path.join(c.path_prefix, '.c/entitlements.xml')
return c
def main():
config = platform_setup()
# parse the command line arguments
parser = argparse.ArgumentParser(description=\
'Extract Adobe CC Typekit fonts. '
'Adobe CC Font Sync syncs your fonts from Typekit, however '
'These fonts are not available')
#parser.add_argument('--install', type=
parser.add_argument('-l', '--list', help='show which fonts are synced')
parser.parse_args()
try:
font_data = get_font_metadata(config.manifest)
pprint(font_data)
except IOError as e:
print("Error: The font manifest could not be found. Make sure Adobe Creative Cloud is running.")
def test():
config = platform_setup()
fonts = get_font_metadata(config.manifest)
extract_fonts(fonts, config.font_dir, 'TEST')
if __name__ == '__main__':
main()