Skip to content

Commit d89b01d

Browse files
committed
Making use of CLI arguments
1 parent c5ee12d commit d89b01d

File tree

7 files changed

+124
-43
lines changed

7 files changed

+124
-43
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,35 @@ This library provides an easy way to generate [*color palettes*](https://www.ety
1212
.. featuring [PANTONE®](https://www.pantone.com), [RAL®](https://www.ral-farben.de), [Dulux®](https://www.dulux.com.au) as well as [Copic®](https://www.copicmarker.com) and [Prismacolor®](https://www.prismacolor.com) (proprietary color spaces). For now, `we-love-colors` creates master palettes for use in [Scribus](https://www.scribus.net), an open source desktop publishing program, as well as [GIMP](https://www.gimp.org) and [Inkscape](https://inkscape.org).
1313

1414
## Getting started
15-
.. was never easier. Make sure Python3 is intalled on your system, then simply do:
15+
Depending on your setup you might prefer a ..
16+
17+
### Local installation via `virtualenv`
18+
Running `setup.sh` will install all dependencies inside a virtual environment, ready for action.
19+
20+
### Global installation via `requirements.txt`
21+
It's as easy as `pip install -r requirements.txt`, but you might want to make sure that Python v3 is installed on your system.
22+
23+
## Usage
24+
Fetching color sets and processing them is really straightforward - for everything else, there's `--help`:
1625

1726
```bash
18-
python3 fetch.py # or any other `fetch*` script
19-
python3 process.py
27+
$ python main.py
28+
Usage: main.py [OPTIONS] COMMAND [ARGS]...
29+
30+
Options:
31+
-v, --version Show the version and exit.
32+
-h, --help Show this message and exit.
33+
34+
Commands:
35+
fetch ARGS: pantone | ral | dulux | copic | prismacolor
36+
process ARGS: pantone | ral | dulux | copic | prismacolor
37+
38+
39+
# Example 1 - Gotta fetch 'em `--all`:
40+
$ python main.py fetch --all && python main.py process --all
41+
42+
# Example 2 - Fetching two sets & processing them:
43+
$ python main.py fetch copic dulux && python main.py process copic dulux # or simply `--all`
2044
```
2145

2246
## Color samples
@@ -48,7 +72,7 @@ We assume neither ownership nor intellectual property of any kind - color codes
4872
- [x] Filtering neons, pastels & metallics
4973
- [x] Adding copyright notice for RAL®/Dulux® (XML + GPL) + fallback option
5074
- [x] Adding examples for all color palettes
51-
- [ ] Making use of CLI arguments
75+
- [x] Making use of CLI arguments
5276
- [x] Automatizing example generation
5377
- [x] Combining all `fetch` scripts
5478
- [x] Cleaning up examples (merge CSS, remove RGB2hex & PHP error settings)

lib/copic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self):
4444
# Valid `set_name` parameter:
4545
# - 'copic', currently 289 colors
4646
##
47-
def fetch(self, set_name):
47+
def fetch(self, set_name='copic'):
4848
# One baseURL to rule them all
4949
base_url = 'https://www.copicmarker.com/collections/collect'
5050

lib/dulux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self):
4343
# Valid `set_name` parameter:
4444
# - 'dulux', currently 1768 colors
4545
##
46-
def fetch(self, set_name):
46+
def fetch(self, set_name='dulux'):
4747
# One baseURL to rule them all
4848
base_url = 'https://colour.dulux.ca/all-colors'
4949

lib/pantone.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ def fetch(self, set_name, firstPage, lastPage):
8787
print('Loading ' + color['code'] + ' in set "' + set_name + '" .. done')
8888

8989

90+
##
91+
# Fetches all PANTONE® colors at once
92+
##
93+
def fetch_all(self):
94+
self.fetch('graphic-design', 1, 32)
95+
self.fetch('fashion-design', 1, 14)
96+
self.fetch('product-design', 1, 10)
97+
98+
9099
##
91100
# Creates JSON files for Dulux® color sets
92101
##

lib/prismacolor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self):
4444
# Valid `set_name` parameter:
4545
# - 'premier', currently 150 colors
4646
##
47-
def fetch(self, set_name):
47+
def fetch(self, set_name='premier'):
4848
# One baseURL to rule them all
4949
base_url = 'https://kredki.eu/pl/p/Prismacolor-Colored-Pencils-Kredki-Art-150-Kol/75'
5050

lib/ral.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from palette import Palette
1717

1818

19-
class Ral(Palette):
19+
class RAL(Palette):
2020
# Dictionary holding fetched colors
2121
sets = {
2222
'classic': [],
@@ -114,3 +114,13 @@ def fetch(self, set_name):
114114
self.sets[identifier].append(color)
115115

116116
print('Loading ' + color['code'] + ' in set "' + set_name + '" .. done')
117+
118+
119+
##
120+
# Fetches all RAL® colors at once
121+
##
122+
def fetch_all(self):
123+
self.fetch('classic')
124+
self.fetch('design')
125+
self.fetch('effect')
126+
self.fetch('plastics')

main.py

Lines changed: 73 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,82 @@
44
# IMPORTS
55
# For more information, see https://www.python.org/dev/peps/pep-0008/#imports
66
##
7+
import click
78

89
from lib.pantone import Pantone
9-
from lib.ral import Ral
10+
from lib.ral import RAL
1011
from lib.dulux import Dulux
1112
from lib.copic import Copic
1213
from lib.prismacolor import Prismacolor
1314

14-
pantone = Pantone()
15-
pantone.fetch('graphic-design', 1, 32)
16-
pantone.fetch('fashion-design', 1, 14)
17-
pantone.fetch('product-design', 1, 10)
18-
pantone.save()
19-
pantone.create_json()
20-
pantone.make_palettes()
21-
22-
ral = Ral()
23-
ral.fetch('classic')
24-
ral.fetch('design')
25-
ral.fetch('effect')
26-
ral.fetch('plastics')
27-
ral.save()
28-
ral.create_json()
29-
ral.make_palettes()
30-
31-
dulux = Dulux()
32-
dulux.fetch('dulux')
33-
dulux.save()
34-
dulux.create_json()
35-
dulux.make_palettes()
36-
37-
copic = Copic()
38-
copic.fetch('copic')
39-
copic.save()
40-
copic.create_json()
41-
copic.make_palettes()
42-
43-
prismacolor = Prismacolor()
44-
prismacolor.fetch('premier')
45-
prismacolor.save()
46-
prismacolor.create_json()
47-
prismacolor.make_palettes()
15+
16+
CONTEXT_SETTINGS = dict(
17+
help_option_names=['-h', '--help'],
18+
)
19+
20+
21+
22+
class_map = {
23+
'dulux': Dulux,
24+
'copic': Copic,
25+
'prismacolor': Prismacolor,
26+
}
27+
28+
@click.group(context_settings=CONTEXT_SETTINGS)
29+
@click.version_option(None, '-v', '--version')
30+
def cli():
31+
pass
32+
33+
@cli.command()
34+
@click.argument('sets', nargs=-1)
35+
@click.option('--all', 'fetch_all', flag_value=True, help='Fetch all available color sets & save as JSON.')
36+
def fetch(sets, fetch_all):
37+
"""
38+
ARGS:
39+
pantone | ral | dulux | copic | prismacolor
40+
"""
41+
valid_sets = list(class_map.keys())
42+
43+
if fetch_all == True:
44+
sets = valid_sets
45+
46+
for set in sets:
47+
if set in valid_sets:
48+
object = class_map[set]()
49+
50+
try:
51+
object.fetch_all()
52+
except AttributeError:
53+
object.fetch()
54+
55+
object.save()
56+
object.create_json()
57+
else:
58+
print('"' + set + '" isn\'t available. Please provide a valid color space,\nsuch as "pantone", "ral", "dulux", "copic" & "prismacolor".')
59+
continue
60+
61+
62+
@cli.command()
63+
@click.argument('sets', nargs=-1)
64+
@click.option('--all', 'process_all', flag_value=True, help='Process all available color sets & generate color palettes.')
65+
def process(sets, process_all):
66+
"""
67+
ARGS:
68+
pantone | ral | dulux | copic | prismacolor
69+
"""
70+
valid_sets = list(class_map.keys())
71+
72+
if process_all == True:
73+
sets = valid_sets
74+
75+
for set in sets:
76+
if set in valid_sets:
77+
object = class_map[set]()
78+
object.make_palettes()
79+
else:
80+
print('"' + set + '" isn\'t available. Please provide a valid color space,\nsuch as "pantone", "ral", "dulux", "copic" & "prismacolor".')
81+
continue
82+
83+
84+
if __name__ == '__main__':
85+
cli()

0 commit comments

Comments
 (0)