-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #786 from googlefonts/tags
font-tags: added
- Loading branch information
Showing
4 changed files
with
480 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
gftools font-tags | ||
Export Font classification tags to csv, or check the spreadsheet | ||
is still structured correctly. | ||
Usage: | ||
# Write tags csv file to google/fonts/tags/all/families.csv | ||
gftools font-tags write path/to/google/fonts | ||
# Check Google Sheet is still structured correctly | ||
gftools font-tags lint path/to/google/fonts | ||
""" | ||
import os | ||
from pathlib import Path | ||
import sys | ||
from gftools.tags import GFTags | ||
from argparse import ArgumentParser | ||
from gftools.utils import is_google_fonts_repo | ||
|
||
|
||
def main(args=None): | ||
parser = ArgumentParser() | ||
subparsers = parser.add_subparsers( | ||
dest="command", required=True, metavar='"write" or "lint"' | ||
) | ||
universal_options_parser = ArgumentParser(add_help=False) | ||
universal_options_parser.add_argument("gf_path", type=Path) | ||
|
||
write_parser = subparsers.add_parser( | ||
"write", | ||
parents=[universal_options_parser], | ||
help="Write Google Sheet to google/fonts csv file", | ||
) | ||
lint_parser = subparsers.add_parser( | ||
"lint", | ||
parents=[universal_options_parser], | ||
help="Check Google Sheet is structured correctly", | ||
) | ||
args = parser.parse_args(args) | ||
|
||
is_google_fonts_repo(args.gf_path) | ||
|
||
gf_tags = GFTags() | ||
|
||
if args.command == "write": | ||
out_dir = args.gf_path / "tags" / "all" | ||
if not out_dir.exists(): | ||
os.makedirs(out_dir) | ||
out = out_dir / "families.csv" | ||
gf_tags.to_csv(out) | ||
elif args.command == "lint": | ||
gf_tags.check_structure() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.