Skip to content

Commit

Permalink
Merging process.py workflow with existing palette.py parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
S1SYPHOS committed May 4, 2019
1 parent a19d6a1 commit db08447
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 113 deletions.
6 changes: 6 additions & 0 deletions lib/copic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Copic(Palette):
# Global JSON path
json_path = './palettes/' + identifier + '/json'

# Copyright notices
copyright = {
'xml': '\n Copic® and related trademarks are the property of\n Too Marker Corporation (https://www.toomarker.co.jp/en)\n ',
'gpl': '##\n# Copic® and related trademarks are the property of\n# Too Marker Corporation (https://www.toomarker.co.jp/en)\n##\n',
}


def __init__(self):
super().__init__()
Expand Down
6 changes: 6 additions & 0 deletions lib/dulux.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Dulux(Palette):
# Global JSON path
json_path = './palettes/' + identifier + '/json'

# Copyright notices
copyright = {
'xml': '\n Dulux® and related trademarks are the property of\n AkzoNobel N.V. (https://www.akzonobel.com) (joint-stock company) (worldwide) or\n DuluxGroup (https://www.dulux.com.au) (Australia & New Zealand) \n ',
'gpl': '##\n# Dulux® and related trademarks are the property of\n# AkzoNobel N.V. (https://www.akzonobel.com) (joint-stock company) (worldwide) or\n# DuluxGroup (https://www.dulux.com.au) (Australia & New Zealand) \n##\n',
}


def __init__(self):
super().__init__()
Expand Down
8 changes: 7 additions & 1 deletion lib/pantone.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class Pantone(Palette):
# Global JSON path
json_path = './palettes/' + identifier + '/json'

# Copyright notices
copyright = {
'xml': '\n PANTONE® and related trademarks are the property of\n Pantone LLC (https://www.pantone.com), a division of X-Rite, a Danaher company\n ',
'gpl': '##\n# PANTONE® and related trademarks are the property of\n# Pantone LLC (https://www.pantone.com), a division of X-Rite, a Danaher company\n##\n'
}


def __init__(self):
super().__init__()
Expand Down Expand Up @@ -325,4 +331,4 @@ def create_json(self, input_filename=''):
with open(json_path, 'w') as file:
file.write(json.dumps(colors, indent=4))

print('%s has been created.' % json_path)
print('Generating %s .. done' % json_path)
6 changes: 6 additions & 0 deletions lib/prismacolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Prismacolor(Palette):
# Global JSON path
json_path = './palettes/' + identifier + '/json'

# Copyright notices
copyright = {
'xml': '\n Prismacolor® and related trademarks are the property of\n Berol Corporation (http://www.berol.co.uk), owned by Sanford L.P. (http://www.sanfordb2b.com),\n a Newell Brands (https://www.newellbrands.com) company\n ',
'gpl': '##\n# Prismacolor® and related trademarks are the property of\n# Berol Corporation (http://www.berol.co.uk), owned by Sanford L.P. (http://www.sanfordb2b.com),\n# a Newell Brands (https://www.newellbrands.com) company\n##\n',
}


def __init__(self):
super().__init__()
Expand Down
6 changes: 6 additions & 0 deletions lib/ral.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class Ral(Palette):
# Global JSON path
json_path = './palettes/' + identifier + '/json'

# Copyright notices
copyright = {
'xml': '\n RAL® and related trademarks are the property of\n RAL gGmbH (https://www.ral-farben.de) (non-profit LLC) or\n RAL Deutsches Institut für Gütesicherung und Kennzeichnung e. V. (https://www.ral.de)\n ',
'gpl': '##\n# RAL® and related trademarks are the property of\n# RAL gGmbH (https://www.ral-farben.de) (non-profit LLC) or\n# RAL Deutsches Institut für Gütesicherung und Kennzeichnung e. V. (https://www.ral.de)\n##\n',
}


def __init__(self):
super().__init__()
Expand Down
5 changes: 5 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
pantone.fetch('product-design', 1, 10)
pantone.save()
pantone.create_json()
pantone.make_palettes()

ral = Ral()
ral.fetch('classic')
Expand All @@ -25,18 +26,22 @@
ral.fetch('plastics')
ral.save()
ral.create_json()
ral.make_palettes()

dulux = Dulux()
dulux.fetch('dulux')
dulux.save()
dulux.create_json()
dulux.make_palettes()

copic = Copic()
copic.fetch('copic')
copic.save()
copic.create_json()
copic.make_palettes()

prismacolor = Prismacolor()
prismacolor.fetch('premier')
prismacolor.save()
prismacolor.create_json()
prismacolor.make_palettes()
84 changes: 83 additions & 1 deletion palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
##

import os
import glob
import json

from lxml import etree


class Palette:
def __init__(self):
Expand Down Expand Up @@ -54,4 +57,83 @@ def create_json(self, input_filename=''):
with open(json_path, 'w') as file:
file.write(json.dumps(colors, indent=4))

print('%s has been created.' % json_path)
print('Generating %s .. done' % json_path)


##
# Makes color palettes in various formats
##
def make_palettes(self):
# Copyright notices
default_copyright = {
'xml': '\n For copyright and other legal information,\n please refer to "README.md" in the root of this project\n ',
'gpl': '##\n# For copyright and other legal information, please refer to "README.md" in the root of this project\n##\n',
}

# Globbing all JSON source files
paths = glob.glob('./palettes/' + self.identifier + '/json/*/*.json', recursive=True)

for path in paths:
file_name = os.path.basename(path).replace('.json', '')

with open(path, 'r') as file:
data = json.load(file)


##
# Building XML color palettes for Scribus
##
root = etree.Element('SCRIBUSCOLORS')
comment = etree.Comment(self.copyright.get('xml', default_copyright['xml']))
root.insert(0, comment)
for color in data:
rgb = color['rgb'][4:-1].split(',')
name = color['name'].title() if color['name'] != '' else color['code']
entry = etree.SubElement(root, 'COLOR')
entry.set('NAME', name)
entry.set('SPACE', 'RGB')
entry.set('R', rgb[0])
entry.set('G', rgb[1])
entry.set('B', rgb[2])

# Creating directories for XML color palettes (if it doesn't exist already)
output_path = os.path.dirname(path).replace('/json', '/xml')
os.makedirs(output_path, exist_ok=True)

# Writing XML color palettes to disk (mirroring JSON source structure)
xml_file = output_path + '/' + file_name + '.xml'
tree = etree.ElementTree(root)
tree.write(xml_file, xml_declaration=True, encoding='UTF-8', pretty_print=True)

print('Generating %s .. done' % xml_file)


##
# Building GPL color palettes for GIMP/Inkscape
##
title = file_name.title() if self.identifier != 'pantone' else file_name.replace('colors', 'Colors')

# Creating directories for GPL color palettes (if it doesn't exist already)
output_path = os.path.dirname(path).replace('/json', '/gpl')
os.makedirs(output_path, exist_ok=True)

# Writing GPL color palettes to disk (mirroring JSON source structure)
gpl_file = output_path + '/' + file_name + '.gpl'

with open(gpl_file, 'w') as file:
file.write('GIMP Palette\n')
file.write('Name: ' + title + '\n')
file.write(self.copyright.get('xml', default_copyright['xml']))
file.write('\n')

for color in data:
name = color['name'].title() if color['name'] != '' else color['code']
line = color['rgb'][4:-1].split(',')

for i in range(len(line)):
line[i] = '{:0>3}'.format(line[i])

line.append(name)
file.write(' '.join(line) + '\n')

print('Generating %s .. done' % gpl_file)
111 changes: 0 additions & 111 deletions process.py

This file was deleted.

0 comments on commit db08447

Please sign in to comment.