-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add subset adder (needs merge of #730)
- Loading branch information
1 parent
2e9c7e1
commit 38b211a
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import sys | ||
from tempfile import NamedTemporaryFile, TemporaryDirectory | ||
|
||
import yaml | ||
|
||
from gftools.builder.file import File | ||
from gftools.builder.operations import OperationBase | ||
|
||
|
||
class AddSubset(OperationBase): | ||
description = "Add a subset from another font" | ||
rule = "gftools-add-ds-subsets -y $yaml -o $out $in" | ||
|
||
def validate(self): | ||
# Ensure there is a new name | ||
if not self.first_source.is_font_source: | ||
raise ValueError("%s is not a font source file" % self.first_source) | ||
if "subsets" not in self.original: | ||
raise ValueError("No subsets defined") | ||
|
||
def convert_dependencies(self, builder): | ||
self._target = TemporaryDirectory() # Stow object | ||
self._orig = NamedTemporaryFile(delete=False, mode="w") | ||
yaml.dump(self.original["subsets"], self._orig) | ||
self._orig.close() | ||
|
||
@property | ||
def targets(self): | ||
dspath = os.path.join(self._target.name, self.first_source.basename.rsplit(".", 1)[0] + ".designspace") | ||
return [ File(dspath) ] | ||
|
||
@property | ||
def variables(self): | ||
return { | ||
"yaml": self._orig.name, | ||
} | ||
|