1 | # -*- coding: utf-8 -*- |
---|
2 | #makeTutorial.py |
---|
3 | ########### SVN repository information ################### |
---|
4 | # $Date: 2018-08-08 21:39:32 +0000 (Wed, 08 Aug 2018) $ |
---|
5 | # $Author: toby $ |
---|
6 | # $Revision: 3559 $ |
---|
7 | # $URL: trunk/makeTutorial.py $ |
---|
8 | # $Id: makeTutorial.py 3559 2018-08-08 21:39:32Z toby $ |
---|
9 | ########### SVN repository information ################### |
---|
10 | ''' |
---|
11 | *makeTutorial: Make Tutorial Web Page* |
---|
12 | --------------------------------------------- |
---|
13 | |
---|
14 | Creates 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 |
---|
16 | index. |
---|
17 | ''' |
---|
18 | |
---|
19 | from __future__ import print_function |
---|
20 | import os |
---|
21 | import requests |
---|
22 | import GSASIIpath |
---|
23 | #import GSASIIctrl as G2G |
---|
24 | |
---|
25 | if __name__ == '__main__': |
---|
26 | GSASIIpath.SetBinaryPath() |
---|
27 | import GSASIIctrlGUI as G2G |
---|
28 | G2BaseURL = G2G.G2BaseURL |
---|
29 | tutorialIndex = G2G.tutorialIndex |
---|
30 | tutURL = G2BaseURL +'/Tutorials' |
---|
31 | outname = os.path.join(GSASIIpath.path2GSAS2,'help','Tutorials.html') |
---|
32 | |
---|
33 | dirList = [l[0] for l in tutorialIndex if len(l) >= 3] |
---|
34 | |
---|
35 | # loop through directories in Tutorials repository |
---|
36 | dirs = [d[:-1] for d in GSASIIpath.svnList(tutURL,False).split('\n') if d and d[-1] == '/'] |
---|
37 | for d in dirs: |
---|
38 | if d not in dirList: print(u"Tutorial directory not in GSASIIctrlGUI.tutorialIndex: "+d) |
---|
39 | |
---|
40 | #import sys |
---|
41 | #out = sys.stdout |
---|
42 | out = open(outname,'w') |
---|
43 | print('<!-- Do not edit this file. It is created by makeTutorial.py from info in GSASIIctrlGUI.py --!>',file=out) |
---|
44 | print('<h2>List of GSAS-II tutorials</H2><UL>',file=out) |
---|
45 | print(''' |
---|
46 | <p> A list of available tutorials appears below. Each tutorial is a |
---|
47 | web page that can be opened using the link below, but most tutorials also need |
---|
48 | to have example data files downloaded. This can also be done with links included below, |
---|
49 | but it can be easier to access tutorials using |
---|
50 | <b>Help/Tutorials</b> menu item. |
---|
51 | When this menu entry is used from inside GSAS-II (unless "browse tutorial on web" is selected), |
---|
52 | the data files are downloaded to a local directory and GSAS-II will start from that directory |
---|
53 | for most file open commands. Most tutorials have also been recorded as videos of the computer screen |
---|
54 | along with naration. Links are provided below where videos are available. |
---|
55 | </p>''',file=out) |
---|
56 | |
---|
57 | videolist = '<UL>' |
---|
58 | for l in tutorialIndex: |
---|
59 | if len(l) == 1: |
---|
60 | print("</UL><h4>{}</H4><UL>".format(l[0]),file=out) |
---|
61 | else: |
---|
62 | pageURL = tutURL+'/'+l[0]+'/'+l[1] |
---|
63 | dataURL = tutURL+'/'+l[0]+'/data' |
---|
64 | suffix = '' |
---|
65 | if l[2][0] == ' ': |
---|
66 | suffix = ' <A href="#prereq">*</A>' |
---|
67 | if suffix: |
---|
68 | print('<UL><LI><A href="{}">{}</A>{}'.format(pageURL,l[2].strip(),suffix),file=out) |
---|
69 | else: |
---|
70 | print('<LI><A href="{}">{}</A>'.format(pageURL,l[2].strip()),file=out) |
---|
71 | |
---|
72 | # check for video tutorial |
---|
73 | vname = 'https://anl.box.com/v/' + os.path.splitext(l[1])[0].replace(' ','')[:30] |
---|
74 | if requests.get(vname).status_code == 200: |
---|
75 | video = '<A href="{}">video</A>'.format(vname) |
---|
76 | #print(' [link: <A href="{}">video</A>]'.format(vname),file=out) |
---|
77 | #print('Found video',vname) |
---|
78 | videolist += '<LI><A href="{}">{}</A></LI>\n'.format(vname,l[2].strip()) |
---|
79 | else: |
---|
80 | video ='' |
---|
81 | print('No video for',vname) |
---|
82 | # check for data |
---|
83 | if GSASIIpath.svnList(dataURL,False): |
---|
84 | exampledata = '<A href="{}">Exercise files</A>'.format(dataURL) |
---|
85 | #print(' [link: <A href="{}">Exercise files</A>].'.format(dataURL),file=out) |
---|
86 | else: |
---|
87 | exampledata = '' |
---|
88 | #print(' [No exercise files].',file=out) |
---|
89 | if video and exampledata: |
---|
90 | print(' [links: {}, {}].'.format(video, exampledata),file=out) |
---|
91 | elif exampledata: |
---|
92 | print(' [link: {}].'.format(exampledata),file=out) |
---|
93 | elif video: |
---|
94 | print(' [link: {}, no example data].'.format(video),file=out) |
---|
95 | else: |
---|
96 | print(' [no example data or video].',file=out) |
---|
97 | |
---|
98 | if len(l) > 3: |
---|
99 | print("<blockquote><I>"+l[3]+"</I></blockquote>",file=out) |
---|
100 | if suffix: print('</UL>',file=out) |
---|
101 | # if l[2][0] == ' ': |
---|
102 | # print(' (Note that this tutorial requires previous as prerequisite)',file=out) |
---|
103 | |
---|
104 | videolist += '</UL>\n' |
---|
105 | print('</UL>\n<A name=prereq>* Indented tutorials require the previous unindented tutorial as a prerequisite',file=out) |
---|
106 | print('<h3>Tutorials with video-recorded examples</H3>', file=out) |
---|
107 | print(videolist, file=out) |
---|
108 | out.close() |
---|