Project

General

Profile

Download (2.17 KB) Statistics
| Branch: | Tag: | Revision:

hydrilla-builder / src / hydrilla / builder / __main__.py @ 16eaeb86

1
# SPDX-License-Identifier: AGPL-3.0-or-later
2

    
3
# Command line interface of Hydrilla package builder.
4
#
5
# This file is part of Hydrilla
6
#
7
# Copyright (C) 2022 Wojtek Kosior
8
#
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
13
#
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
# GNU Affero General Public License for more details.
18
#
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
21
#
22
#
23
# I, Wojtek Kosior, thereby promise not to sue for violation of this
24
# file's license. Although I request that you do not make use this code
25
# in a proprietary program, I am not going to enforce this in court.
26

    
27
from pathlib import Path
28

    
29
import click
30

    
31
from .build import Build
32

    
33
def validate_dir_path(ctx, param, value):
34
    path = Path(value)
35
    if path.is_dir():
36
        return path.resolve()
37

    
38
    raise click.BadParameter(f'{param.human_readable_name} must be a directory path')
39

    
40
def validate_path(ctx, param, value):
41
    return Path(value)
42

    
43
@click.command()
44
@click.option('-s', '--srcdir', default='.', type=click.Path(),
45
              callback=validate_dir_path,
46
              help='Source directory to build from.')
47
@click.option('-i', '--index-json', default='index.json', type=click.Path(),
48
              callback=validate_path,
49
              help='Path to file to be processed instead of index.json (if not absolute, resolved relative to srcdir).')
50
@click.option('-d', '--dstdir', type=click.Path(), required=True,
51
              callback=validate_dir_path,
52
              help='Destination directory to write built package files to.')
53
def preform_build(srcdir, index_json, dstdir):
54
    """
55
    Build Hydrilla package from scrdir and write the resulting files under
56
    dstdir.
57
    """
58
    build = Build(srcdir, index_json)
59
    build.write_package_files(dstdir)
60

    
61
preform_build()
(2-2/4)