File: build_usersguide.py

package info (click to toggle)
vistrails 3.0~git%2B9dc22bd-2
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 62,860 kB
  • sloc: python: 314,054; xml: 42,697; sql: 4,113; php: 731; sh: 469; makefile: 253
file content (177 lines) | stat: -rwxr-xr-x 7,721 bytes parent folder | download | duplicates (2)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/python3
###############################################################################
##
## Copyright (C) 2014-2016, New York University.
## Copyright (C) 2011-2014, NYU-Poly.
## Copyright (C) 2006-2011, University of Utah.
## All rights reserved.
## Contact: contact@vistrails.org
##
## This file is part of VisTrails.
##
## "Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are met:
##
##  - Redistributions of source code must retain the above copyright notice,
##    this list of conditions and the following disclaimer.
##  - Redistributions in binary form must reproduce the above copyright
##    notice, this list of conditions and the following disclaimer in the
##    documentation and/or other materials provided with the distribution.
##  - Neither the name of the New York University nor the names of its
##    contributors may be used to endorse or promote products derived from
##    this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
## OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
## OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
###############################################################################
""" This will build the html and the pdf version of the user's guide and put
them in where defined. 
Please configure the variables below according to your server's setup

"""
import os
import os.path
import re
import shutil
import subprocess
import sys
import time
### Begin configuration ###

# Should we build the pdf version
BUILD_PDF = True

# Should we build the html version
BUILD_HTML = False

# Folder where vistrails is
PATH_TO_VISTRAILS_GIT = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))

# Folder where the html files will be placed. This script will build
# the docs in the standard location and move files later
HTML_FOLDER = None

# Complete file path to where copy final pdf file
PDF_FILE = os.path.join(PATH_TO_VISTRAILS_GIT, "scripts", "VisTrails.pdf")

# Should we run a `git pull` before building docs? 
PERFORM_GIT_PULL = False

### End configuration ### 
### The following variables usually don't need to be changed
USERSGUIDE_SUBPATH = ['doc', 'usersguide']
GIT_PULL_CMD = ["git", "pull"]
BUILD_HTML_SUBPATH = ["_build", "html"]
BUILD_LATEX_SUBPATH = ["_build", "latex"]
PDF_BUILD_NAME = "VisTrails.pdf"
if len(sys.argv)>1:
    PDF_FILE = os.path.abspath(sys.argv[1])
    if PDF_FILE[-4:] != '.pdf':
        PDF_FILE = os.path.join(PDF_FILE, PDF_BUILD_NAME)
if __name__ == '__main__':
    if (PATH_TO_VISTRAILS_GIT is not None and
        os.path.exists(PATH_TO_VISTRAILS_GIT)):
        current_folder = os.getcwd()
        if PERFORM_GIT_PULL:
            print("performing git pull in %s..."%PATH_TO_VISTRAILS_GIT)
            os.chdir(PATH_TO_VISTRAILS_GIT)
            proc = subprocess.Popen(GIT_PULL_CMD,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
            proc.wait()
            if proc.returncode != 0:
                print("ERROR: git pull failed.")
                if proc.stdout:
                    print(proc.stdout.readlines())
        
        # The api needs path to source set
        env = os.environ.copy()
        env['PYTHONPATH'] = PATH_TO_VISTRAILS_GIT

        os.chdir(os.path.join(PATH_TO_VISTRAILS_GIT,
                              *USERSGUIDE_SUBPATH))
        
        print("Going into directory %s"%os.getcwd())
        if BUILD_HTML:
            # now build html documentation    
            print("now building html documentation...")
            proc = subprocess.Popen(["make", "html"],
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    env=env)
            proc.wait()
            if proc.returncode != 0:
                print("ERROR: make html failed.")
                if proc.stdout:
                    print(proc.stdout.readlines())
            else:
                # now move files to their final place
                if HTML_FOLDER is not None:
                    if os.path.exists(HTML_FOLDER):
                        shutil.rmtree(HTML_FOLDER)
                    html_build = os.path.join(os.getcwd(),
                                              *BUILD_HTML_SUBPATH)
                    shutil.move(html_build, HTML_FOLDER)

        if BUILD_PDF:
            print("Building usersguide to ", PDF_FILE)
            #build latex files
            print("now preparing latex files...")
            latex_path = os.path.join(".",
                                  *BUILD_LATEX_SUBPATH)
            if os.path.exists(latex_path):
                print("removing old %s directory..."%latex_path)
                proc = subprocess.Popen(["rm", "-rf", latex_path],
                                        stdin=subprocess.PIPE,
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.STDOUT)
                proc.wait()
            print("building latex files...")
            proc = subprocess.Popen(["make", "latex"],
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    env=env)
            proc.wait()
            if proc.returncode != 0:
                print("ERROR: make latex failed.")
                if proc.stdout:
                    print(proc.stdout.readlines())
            else:
                #now build pdf
                print("now building pdf file...")
                os.chdir(os.path.join(os.getcwd(),
                         *BUILD_LATEX_SUBPATH))
                proc = subprocess.Popen(["make", "LATEXOPTS=-interaction=nonstopmode -halt-on-error", "all-pdf"],
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT,
                                    env=env)
                output, error = proc.communicate()
                if proc.returncode != 0:
                    print("ERROR: make all-pdf failed.")
                    print(output, error)
                else:
                    #now move file to its final place
                    if PDF_FILE is not None:
                        if os.path.exists(PDF_FILE):
                            os.unlink(PDF_FILE)
                        pdf_build = os.path.join(os.getcwd(),
                                                 PDF_BUILD_NAME)
                        shutil.move(pdf_build, PDF_FILE)
        os.chdir(current_folder)
        print("Done.")
    else:
        print("PATH_TO_VISTRAILS_GIT was not provided. Exiting.")