source: trunk/makeTutorial.py

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

save GPX before OnFileSave?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 7.1 KB
Line 
1# -*- coding: utf-8 -*-
2#makeTutorial.py
3########### SVN repository information ###################
4# $Date: 2021-03-08 23:05:59 +0000 (Mon, 08 Mar 2021) $
5# $Author: toby $
6# $Revision: 4846 $
7# $URL: trunk/makeTutorial.py $
8# $Id: makeTutorial.py 4846 2021-03-08 23:05:59Z 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        print('.', end='', flush=True)
94        if len(l) == 1:
95            print("</UL><h4>{}</H4><UL>".format(l[0]),file=out)
96        else:
97            tutorialcount += 1
98            pageURL = tutURL+'/'+l[0]+'/'+l[1]
99            dataURL = tutURL+'/'+l[0]+'/data'
100            suffix = ''
101            if l[2][0] == ' ':
102                suffix = ' <A href="#prereq">*</A>'
103            if suffix: 
104                print('<UL><LI><A href="{}">{}</A>{}'.format(pageURL,l[2].strip(),suffix),file=out)
105            else:
106                print('<LI><A href="{}">{}</A>'.format(pageURL,l[2].strip()),file=out)
107           
108            # check for video tutorial
109            videoName = '{:-<12s}'.format(
110                os.path.splitext(l[1])[0].replace(' ','')[:30])           
111            vname = 'https://anl.box.com/v/{}'.format(videoName)
112            #if requests.get(vname).status_code == 200:
113            if vname in onlineVideos:
114                videocount += 1
115                video = '<A href="{}">video</A>'.format(vname)
116                #print(' [link: <A href="{}">video</A>]'.format(vname),file=out)
117                #print('Found video',vname)
118                videolist += '<LI><A href="{}">{}</A></LI>\n'.format(vname,l[2].strip())
119            else:
120                video =''
121                novideo += '\n{:45s}{}'.format(videoName,l[2])
122            # check for data
123            if GSASIIpath.svnList(dataURL,False):
124                exampledata = '<A href="{}">Exercise files</A>'.format(dataURL)
125                #print(' [link: <A href="{}">Exercise files</A>].'.format(dataURL),file=out)
126            else:
127                exampledata = ''
128                #print(' [No exercise files].',file=out)
129            if video and exampledata:
130                print(' [links: {}, {}].'.format(video, exampledata),file=out)
131            elif exampledata:
132                print(' [link: {}].'.format(exampledata),file=out)
133            elif video:
134                print(' [link: {}, no example data].'.format(video),file=out)
135            else:
136                print(' [no example data or video].',file=out)
137               
138            if len(l) > 3:
139                print("<blockquote><I>"+l[3]+"</I></blockquote>",file=out)
140            if suffix: print('</UL>',file=out)
141    #        if l[2][0] == ' ':
142    #            print(' (Note that this tutorial requires previous as prerequisite)',file=out)
143
144    videolist += '</UL>\n'
145    print('</UL>\n<A name=prereq>* Indented tutorials require the previous unindented tutorial as a prerequisite',file=out)
146    print('<h3>Tutorials with video-recorded examples</H3>', file=out)
147    print(videolist, file=out)
148    print("<P>The video tutorials are also <A href=https://pan.baidu.com/s/1C1jq1amfuVmcY2n91cQcsg> mirrored in China</A></P>",
149                  file=out)
150    out.close()
151    print("\nTutorials without videos",novideo)
152
153    print("\nStatistics: {} total tutorials, {} with videos"
154              .format(tutorialcount,videocount))
Note: See TracBrowser for help on using the repository browser.