File size: 2,296 Bytes
68ce2fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python

# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:

#
#  Author(s):  Andrew LaMora
#  Created on: 2005-09-06
#
#  (C) Copyright 2005-2025 Johns Hopkins University (JHU), All Rights Reserved.

# --- begin cisst license - do not edit ---
# 
# This software is provided "as is" under an open source license, with
# no warranty.  The complete license can be found in license.txt and
# http://www.cisst.org/cisst/license.txt.
# 
# --- end cisst license ---

# Python script file to compile Python source files (*.py) and create
# Python binary files (*.pyc).  This script file requires two
# command line arguments:
# 
#    src-dir    Directory for the input source files (*.py)
#    dest-dir   Directory for the output binary files (*.py)
#
# If an error occurs (e.g., could not delete file, create directory, etc.)
# the script exits with a non-zero return code.


"""makeIrepy src-dir  dest-dir

This module compiles the source files of the IRE IDE into the
appropriate destination (release) directory.
"""
import os, sys, glob, py_compile
#import shutil

def main():
    if len(sys.argv)<3:
        print('Syntax:  python %s src-dir dest-dir' % sys.argv[0])
        sys.exit(1)

    src = sys.argv[1]
    dest = sys.argv[2]

    # remove all .pyc files in destination directory
    # (this won't fail even if the directory does not exist)
    try:
       map(os.remove, glob.glob(os.path.join(dest,'*.pyc')))
    except OSError as e:
       print('makeIrepy: could not delete ' + e.filename + ', ' + e.strerror)
       sys.exit(1)

    # create the directory (if it does not already exist)
    if not os.path.isdir(dest):
        try:
           os.makedirs(dest)
        except OSError as e:
           print('makeIrepy: could not create destination directory: ' + dest)
           print(e)
           sys.exit(1)

    # compile the source files
    for fpath in glob.glob(os.path.join(src,'*.py')):
        fname = os.path.basename(fpath)
        py_compile.compile(fpath, os.path.join(dest,fname+'c'))
    
    #Now copy the images over.
    #This can be directly handled by CMake
    #shutil.copytree(os.path.join(src,'images', os.path.join(dest, 'images')))
    
if __name__ == "__main__":
    main()