source: trunk/makeTutorial.py @ 4654

Last change on this file since 4654 was 4654, checked in by toby, 11 months ago

new video tutorial; misc minor RB GUI fixes for Windows; option to show GPX sizes; remove use of deprecated imp module

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