source: trunk/makeTutorial.py @ 3552

Last change on this file since 3552 was 3552, checked in by toby, 5 years ago

start adding video tutorials

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 3.5 KB
Line 
1# -*- coding: utf-8 -*-
2#makeTutorial.py
3########### SVN repository information ###################
4# $Date: 2018-08-03 03:03:06 +0000 (Fri, 03 Aug 2018) $
5# $Author: toby $
6# $Revision: 3552 $
7# $URL: trunk/makeTutorial.py $
8# $Id: makeTutorial.py 3552 2018-08-03 03:03:06Z 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
21import requests
22import GSASIIpath
23#import GSASIIctrl as G2G
24
25if __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.
54    </p>''',file=out)
55
56    for l in tutorialIndex:
57        if len(l) == 1:
58            print("</UL><h4>{}</H4><UL>".format(l[0]),file=out)
59        else:
60            pageURL = tutURL+'/'+l[0]+'/'+l[1]
61            dataURL = tutURL+'/'+l[0]+'/data'
62            suffix = ''
63            if l[2][0] == ' ':
64                suffix = ' <A href="#prereq">*</A>'
65            if suffix: 
66                print('<UL><LI><A href="{}">{}</A>{}'.format(pageURL,l[2].strip(),suffix),file=out)
67            else:
68                print('<LI><A href="{}">{}</A>'.format(pageURL,l[2].strip()),file=out)
69           
70            # check for video tutorial
71            vname = 'https://anl.box.com/v/' + os.path.splitext(l[1])[0].replace(' ','')[:30]
72            if requests.get(vname).status_code == 200:
73                print(' [link: <A href="{}">video</A>]'.format(vname),file=out)
74                #print('Found video',vname)
75            else:
76                print('No video',vname)
77            if GSASIIpath.svnList(dataURL,False):
78                print(' [link: <A href="{}">Exercise files</A>].'.format(dataURL),file=out)
79            else:
80                print(' [No exercise files].',file=out)
81            if len(l) > 3:
82                print("<blockquote><I>"+l[3]+"</I></blockquote>",file=out)
83            if suffix: print('</UL>',file=out)
84    #        if l[2][0] == ' ':
85    #            print(' (Note that this tutorial requires previous as prerequisite)',file=out)
86
87    print('</UL>\n<A name=prereq>* Indented tutorials require the previous unindented tutorial as a prerequisite',file=out)
88    out.close()
Note: See TracBrowser for help on using the repository browser.