PyXMake Developer Guide: src/PyXMake/VTL/archive.py Source File

| PyXMake Developer Guide 1.0 PyXMake

Loading...
Searching...
No Matches
archive.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Triple-use minimum working example for PyXMake. This script can be
7executed in three different ways in varying levels of accessibility
8
9@note: Compile a stand-alone application using PyInstaller
10Created on 02.05.2020
11
12@version: 1.0
13----------------------------------------------------------------------------------------------
14@requires:
15 - PyXMake
16
17@change:
18 - Requires PyCODAC in PYTHONPATH.
19
20@author: garb_ma [DLR-FA,STM Braunschweig]
21----------------------------------------------------------------------------------------------
22"""
23import os, sys
24import argparse
25
26try:
27 import PyXMake as _ #@UnusedImport
28except ImportError:
29 # Script is executed as a plug-in
30 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
31finally:
32 import PyXMake
33 # Get absolute package paths
34 __pyx_src_path = PyXMake.PyXMakePath
35 # Import all module dependencies
36 from PyXMake.Tools import Utility
37 from PyXMake.Build.Make import AllowDefaultMakeOption
38
39 def main(
40 BuildID,
41 # Resource paths
42 source=__pyx_src_path,
43 # Define output path
44 output=os.getcwd(),
45 # Default file extensions to be excluded from the final archive
46 exclude = [".git", ".svn", "__pycache__"],
47 # Additional keyword arguments
48 **kwargs):
49 """
50 Main function to execute the script.
51 """
52 # Create an archive from the given path.
53 Utility.CreateArchive(os.path.join(output,BuildID), source=source, exclude=exclude)
54 pass
55
56if __name__ == "__main__":
57# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58# % Access command line inputs %
59# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 # Process all known arguments
61 parser = argparse.ArgumentParser(description='CLI wrapper options for archive generator.')
62 parser.add_argument('name', type=str, nargs=1, help="Name of the archive")
63 parser.add_argument('source', type=str, nargs=1, help="Absolute path to source directory.")
64 parser.add_argument("--output", type=str, nargs=1, help="Absolute path to output directory. Defaults to the current workspace.")
65 parser.add_argument("--exclude", nargs='+', default=[], help="File extensions to be ignored during the process")
66 # Check all options or run unit tests in default mode
67 try:
68 # Check CLI options
69 _ = sys.argv[1]
70 args, _ = parser.parse_known_args()
71 # Archive output name is mandatory
72 project = args.name[0] ;
73 # Specification is mandatory
74 source = args.source[0] ;
75 # Optional non-default output directory
76 try: output = args.output[0]
77 except: output = os.path.abspath(os.getcwd())
78 # Optional non-default exclude pattern
79 try: excludes = args.exclude
80 except: excludes = [".git", ".svn", "__pycache__"]
81 # Use an exception to allow help message to be printed.
82 except Exception as _:
83 # Run default function call for unit test coverage
84 if AllowDefaultMakeOption: main("pyx_core-master.zip")
85 # Execute valid CLI command
86 else: main(project, source, output, exclude=excludes)
87 # Finish
88 print("==================================")
89 print("Finished creating archive")
90 print("==================================")
PyXMake.Build.Make
Create a make object to define the building environment.
Definition Make.py:1
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
PyXMake.VTL.archive.main
main(BuildID, source=__pyx_src_path, output=os.getcwd(), exclude=[".git", ".svn", "__pycache__"], **kwargs)
Definition archive.py:48