source: trunk/makeTutorial.py @ 4845

Last change on this file since 4845 was 4845, checked in by toby, 7 months ago

Tutorial #50 now in web page

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 7.0 KB
Line 
1# -*- coding: utf-8 -*-
2#makeTutorial.py
3########### SVN repository information ###################
4# $Date: 2021-03-08 19:02:40 +0000 (Mon, 08 Mar 2021) $
5# $Author: toby $
6# $Revision: 4845 $
7# $URL: trunk/makeTutorial.py $
8# $Id: makeTutorial.py 4845 2021-03-08 19:02:40Z 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')
54onlineVideos.append('https://anl.box.com/v/RigidBodyRef')
55#onlineVideos.append('
56
57if __name__ == '__main__':
58    GSASIIpath.SetBinaryPath()
59    import GSASIIctrlGUI as G2G
60    G2BaseURL = G2G.G2BaseURL
61    tutorialIndex = G2G.tutorialIndex
62    tutURL = G2BaseURL +'/Tutorials'
63    outname = os.path.join(GSASIIpath.path2GSAS2,'help','Tutorials.html')
64
65    dirList = [l[0] for l in tutorialIndex if len(l) >= 3]
66
67    # loop through directories in Tutorials repository
68    dirs = [d[:-1] for d in GSASIIpath.svnList(tutURL,False).split('\n') if d and d[-1] == '/']   
69    for d in dirs:
70        if d not in dirList: print(u"Tutorial directory not in GSASIIctrlGUI.tutorialIndex: "+d)
71
72    #import sys
73    #out = sys.stdout
74    out = open(outname,'w')
75    print('<!-- Do not edit this file. It is created by makeTutorial.py from info in GSASIIctrlGUI.py --!>',file=out)
76    print('<h2>List of GSAS-II tutorials</H2><UL>',file=out)
77    print('''
78    <p> A list of available tutorials appears below. Each tutorial is a
79    web page that can be opened using the link below, but most tutorials also need
80    to have example data files downloaded. This can also be done with links included below,
81    but it can be easier to access tutorials using
82    <b>Help/Tutorials</b> menu item.
83    When this menu entry is used from inside GSAS-II (unless "browse tutorial on web" is selected),
84    the data files are downloaded to a local directory and GSAS-II will start from that directory
85    for most file open commands. Most tutorials have also been recorded as videos of the computer screen
86    along with naration. Links are provided below where videos are available.
87    </p>''',file=out)
88    novideo = ''
89    videocount = 0
90    tutorialcount = 0
91    videolist = '<UL>'
92    for l in tutorialIndex:
93        if len(l) == 1:
94            print("</UL><h4>{}</H4><UL>".format(l[0]),file=out)
95        else:
96            tutorialcount += 1
97            pageURL = tutURL+'/'+l[0]+'/'+l[1]
98            dataURL = tutURL+'/'+l[0]+'/data'
99            suffix = ''
100            if l[2][0] == ' ':
101                suffix = ' <A href="#prereq">*</A>'
102            if suffix: 
103                print('<UL><LI><A href="{}">{}</A>{}'.format(pageURL,l[2].strip(),suffix),file=out)
104            else:
105                print('<LI><A href="{}">{}</A>'.format(pageURL,l[2].strip()),file=out)
106           
107            # check for video tutorial
108            videoName = '{:-<12s}'.format(
109                os.path.splitext(l[1])[0].replace(' ','')[:30])           
110            vname = 'https://anl.box.com/v/{}'.format(videoName)
111            #if requests.get(vname).status_code == 200:
112            if vname in onlineVideos:
113                videocount += 1
114                video = '<A href="{}">video</A>'.format(vname)
115                #print(' [link: <A href="{}">video</A>]'.format(vname),file=out)
116                #print('Found video',vname)
117                videolist += '<LI><A href="{}">{}</A></LI>\n'.format(vname,l[2].strip())
118            else:
119                video =''
120                novideo += '\n{:45s}{}'.format(videoName,l[2])
121            # check for data
122            if GSASIIpath.svnList(dataURL,False):
123                exampledata = '<A href="{}">Exercise files</A>'.format(dataURL)
124                #print(' [link: <A href="{}">Exercise files</A>].'.format(dataURL),file=out)
125            else:
126                exampledata = ''
127                #print(' [No exercise files].',file=out)
128            if video and exampledata:
129                print(' [links: {}, {}].'.format(video, exampledata),file=out)
130            elif exampledata:
131                print(' [link: {}].'.format(exampledata),file=out)
132            elif video:
133                print(' [link: {}, no example data].'.format(video),file=out)
134            else:
135                print(' [no example data or video].',file=out)
136               
137            if len(l) > 3:
138                print("<blockquote><I>"+l[3]+"</I></blockquote>",file=out)
139            if suffix: print('</UL>',file=out)
140    #        if l[2][0] == ' ':
141    #            print(' (Note that this tutorial requires previous as prerequisite)',file=out)
142
143    videolist += '</UL>\n'
144    print('</UL>\n<A name=prereq>* Indented tutorials require the previous unindented tutorial as a prerequisite',file=out)
145    print('<h3>Tutorials with video-recorded examples</H3>', file=out)
146    print(videolist, file=out)
147    print("<P>The video tutorials are also <A href=https://pan.baidu.com/s/1C1jq1amfuVmcY2n91cQcsg> mirrored in China</A></P>",
148                  file=out)
149    out.close()
150    print("Tutorials without videos",novideo)
151
152    print("\nStatistics: {} total tutorials, {} with videos"
153              .format(tutorialcount,videocount))
Note: See TracBrowser for help on using the repository browser.