blob: 80d5cbfda69a47b76b2e94840e1f2f998e9ab42c (
plain)
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
|
# MenuTitle: TypArichive
__doc__="""
Moves the current font to an `_archive` directory and opens a new timestamped
copy.
"""
# Copyright (c) 2018 Teddy Wing
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from datetime import datetime
from os import path
import re
import shutil
def new_font_name(filename, time_string):
return re.sub(r'\d{12}', time_string, filename)
font = Glyphs.font
filepath = font.filepath
time_string = datetime.now().strftime('%Y%m%d%H%M')
font_directory = path.dirname(filepath)
archive_directory = path.join(font_directory, '_archive')
new_font_path = path.join(
font_directory,
new_font_name(
path.basename(filepath),
time_string))
shutil.copy2(filepath, new_font_path)
shutil.move(filepath, archive_directory)
font.close()
Glyphs.open(new_font_path)
Glyphs.font.familyName = new_font_name(
Glyphs.font.familyName,
time_string)
|