source: trunk/makeTutorial.py @ 4131

Last change on this file since 4131 was 4131, checked in by toby, 4 years ago

restore videos, deal with failure to test if box.com files are present

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 6.7 KB
Line 
1# -*- coding: utf-8 -*-
2#makeTutorial.py
3########### SVN repository information ###################
4# $Date: 2019-09-02 15:29:27 +0000 (Mon, 02 Sep 2019) $
5# $Author: toby $
6# $Revision: 4131 $
7# $URL: trunk/makeTutorial.py $
8# $Id: makeTutorial.py 4131 2019-09-02 15:29:27Z toby $
9########### SVN repository information ###################
10'''
11*makeTutorial: Make Tutorial Web Page*
12---------------------------------------------
13
14Creates an HTML page (``GSASII/help/Tutorials.html``) listing all the tutorials in
15:data:`GSASIIctrlGUI.tutorialIndex`. Run this after adding a new tutorial to that
16index.
17'''
18
19from __future__ import print_function
20import os
21#import requests
22import GSASIIpath
23#import GSASIIctrl as G2G
24onlineVideos = []
25'''a list of videos that are in box, since I don't know how to check if they
26are present anymore
27'''
28onlineVideos.append('https://anl.box.com/v/CalibrationofanareadetectorinG')
29onlineVideos.append('https://anl.box.com/v/CalibrationTutorial')
30onlineVideos.append('https://anl.box.com/v/CalibrationofaTOFpowderdiffrac')
31onlineVideos.append('https://anl.box.com/v/Combinedrefinement')
32onlineVideos.append('https://anl.box.com/v/TOFcombinedXNRietveldrefinemen')
33onlineVideos.append('https://anl.box.com/v/NeutronCWPowderData')
34onlineVideos.append('https://anl.box.com/v/FindProfParamCW')
35onlineVideos.append('https://anl.box.com/v/DeterminingWavelength')
36onlineVideos.append('https://anl.box.com/v/FitPeaks----')
37onlineVideos.append('https://anl.box.com/v/LaboratoryX-')
38onlineVideos.append('https://anl.box.com/v/FittingSmallAngleScatteringDat')
39onlineVideos.append('https://anl.box.com/v/FitBkgTut---')
40onlineVideos.append('https://anl.box.com/v/SmallAngleImageProcessing')
41onlineVideos.append('https://anl.box.com/v/Integrationofareadetectordatai')
42onlineVideos.append('https://anl.box.com/v/MerohedraltwinrefinementinGSAS')
43onlineVideos.append('https://anl.box.com/v/ParametricFitting')
44onlineVideos.append('https://anl.box.com/v/SequentialRefinementofSmallAng')
45onlineVideos.append('https://anl.box.com/v/SequentialTutorial')
46onlineVideos.append('https://anl.box.com/v/SimpleMagnetic')
47onlineVideos.append('https://anl.box.com/v/SimTutorial-')
48onlineVideos.append('https://anl.box.com/v/SmallAngleSizeDistribution')
49onlineVideos.append('https://anl.box.com/v/StackingFaults-I')
50onlineVideos.append('https://anl.box.com/v/StartingGSAS')
51onlineVideos.append('https://anl.box.com/v/Strainfittingof2DdatainGSAS-II')
52onlineVideos.append('https://anl.box.com/v/Textureanalysisof2DdatainGSAS-')
53onlineVideos.append('https://anl.box.com/v/TOFSequentialSinglePeakFit')
54#onlineVideos.append('
55
56if __name__ == '__main__':
57    GSASIIpath.SetBinaryPath()
58    import GSASIIctrlGUI as G2G
59    G2BaseURL = G2G.G2BaseURL
60    tutorialIndex = G2G.tutorialIndex
61    tutURL = G2BaseURL +'/Tutorials'
62    outname = os.path.join(GSASIIpath.path2GSAS2,'help','Tutorials.html')
63
64    dirList = [l[0] for l in tutorialIndex if len(l) >= 3]
65
66    # loop through directories in Tutorials repository
67    dirs = [d[:-1] for d in GSASIIpath.svnList(tutURL,False).split('\n') if d and d[-1] == '/']   
68    for d in dirs:
69        if d not in dirList: print(u"Tutorial directory not in GSASIIctrlGUI.tutorialIndex: "+d)
70
71    #import sys
72    #out = sys.stdout
73    out = open(outname,'w')
74    print('<!-- Do not edit this file. It is created by makeTutorial.py from info in GSASIIctrlGUI.py --!>',file=out)
75    print('<h2>List of GSAS-II tutorials</H2><UL>',file=out)
76    print('''
77    <p> A list of available tutorials appears below. Each tutorial is a
78    web page that can be opened using the link below, but most tutorials also need
79    to have example data files downloaded. This can also be done with links included below,
80    but it can be easier to access tutorials using
81    <b>Help/Tutorials</b> menu item.
82    When this menu entry is used from inside GSAS-II (unless "browse tutorial on web" is selected),
83    the data files are downloaded to a local directory and GSAS-II will start from that directory
84    for most file open commands. Most tutorials have also been recorded as videos of the computer screen
85    along with naration. Links are provided below where videos are available.
86    </p>''',file=out)
87
88    videolist = '<UL>'
89    for l in tutorialIndex:
90        if len(l) == 1:
91            print("</UL><h4>{}</H4><UL>".format(l[0]),file=out)
92        else:
93            pageURL = tutURL+'/'+l[0]+'/'+l[1]
94            dataURL = tutURL+'/'+l[0]+'/data'
95            suffix = ''
96            if l[2][0] == ' ':
97                suffix = ' <A href="#prereq">*</A>'
98            if suffix: 
99                print('<UL><LI><A href="{}">{}</A>{}'.format(pageURL,l[2].strip(),suffix),file=out)
100            else:
101                print('<LI><A href="{}">{}</A>'.format(pageURL,l[2].strip()),file=out)
102           
103            # check for video tutorial
104            videoName = '{:-<12s}'.format(
105                os.path.splitext(l[1])[0].replace(' ','')[:30])           
106            vname = 'https://anl.box.com/v/{}'.format(videoName)
107            #if requests.get(vname).status_code == 200:
108            if vname in onlineVideos:
109                video = '<A href="{}">video</A>'.format(vname)
110                #print(' [link: <A href="{}">video</A>]'.format(vname),file=out)
111                #print('Found video',vname)
112                videolist += '<LI><A href="{}">{}</A></LI>\n'.format(vname,l[2].strip())
113            else:
114                video =''
115                print('No video for {:45s}{}'.format(videoName,l[2]))
116            # check for data
117            if GSASIIpath.svnList(dataURL,False):
118                exampledata = '<A href="{}">Exercise files</A>'.format(dataURL)
119                #print(' [link: <A href="{}">Exercise files</A>].'.format(dataURL),file=out)
120            else:
121                exampledata = ''
122                #print(' [No exercise files].',file=out)
123            if video and exampledata:
124                print(' [links: {}, {}].'.format(video, exampledata),file=out)
125            elif exampledata:
126                print(' [link: {}].'.format(exampledata),file=out)
127            elif video:
128                print(' [link: {}, no example data].'.format(video),file=out)
129            else:
130                print(' [no example data or video].',file=out)
131               
132            if len(l) > 3:
133                print("<blockquote><I>"+l[3]+"</I></blockquote>",file=out)
134            if suffix: print('</UL>',file=out)
135    #        if l[2][0] == ' ':
136    #            print(' (Note that this tutorial requires previous as prerequisite)',file=out)
137
138    videolist += '</UL>\n'
139    print('</UL>\n<A name=prereq>* Indented tutorials require the previous unindented tutorial as a prerequisite',file=out)
140    print('<h3>Tutorials with video-recorded examples</H3>', file=out)
141    print(videolist, file=out)
142    print("<P>The video tutorials are also <A href=https://pan.baidu.com/s/1C1jq1amfuVmcY2n91cQcsg> mirrored in China</A></P>",
143                  file=out)
144    out.close()
Note: See TracBrowser for help on using the repository browser.