PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Tools/wiki2qhelp.py

https://github.com/emagdalena/FreeCAD
Python | 622 lines | 557 code | 22 blank | 43 comment | 37 complexity | 89fc4b01d50408b093fa8b1b8cf2e680 MD5 | raw file
Possible License(s): LGPL-2.0, BSD-3-Clause
  1. #!/usr/bin/env python
  2. #***************************************************************************
  3. #* *
  4. #* Copyright (c) 2009 Yorik van Havre <yorik@uncreated.net> *
  5. #* *
  6. #* This program is free software; you can redistribute it and/or modify *
  7. #* it under the terms of the GNU Library General Public License (LGPL) *
  8. #* as published by the Free Software Foundation; either version 2 of *
  9. #* the License, or (at your option) any later version. *
  10. #* for detail see the LICENCE text file. *
  11. #* *
  12. #* This program is distributed in the hope that it will be useful, *
  13. #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. #* GNU Library General Public License for more details. *
  16. #* *
  17. #* You should have received a copy of the GNU Library General Public *
  18. #* License along with this program; if not, write to the Free Software *
  19. #* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
  20. #* USA *
  21. #* *
  22. #***************************************************************************
  23. __title__="wiki2qhelp"
  24. __author__ = "Yorik van Havre <yorik@uncreated.net>"
  25. __url__ = "http://yorik.uncreated.net"
  26. """
  27. This script retrieves the contents of a wiki site and saves it locally,
  28. then calls qt help compiler to produce a qhelp-assistant help file.
  29. The script can be called without arguments, it will then use the default
  30. url below, or by passing it an url and optionally a TOC name.
  31. """
  32. import sys, os, re, tempfile, getopt
  33. from urllib2 import urlopen, HTTPError
  34. # CONFIGURATION #################################################
  35. DEFAULTURL = "http://sourceforge.net/apps/mediawiki/free-cad" #default URL if no URL is passed
  36. INDEX = "Online_Help_Toc" # the start page from where to crawl the wiki
  37. NORETRIEVE = ['Manual','Developer_hub','Power_users_hub','Users_hub','Source_documentation', 'User_hub','Main_Page','About_this_site'] # pages that won't be fetched (kept online)
  38. GETTRANSLATIONS = True # Set true if you want to get the translations too.
  39. MAXFAIL = 3 # max number of retries if download fails
  40. VERBOSE = True # to display what's going on. Otherwise, runs totally silent.
  41. COMPILE = True # Wether qt assistant will be used to compile the final help file
  42. OUTPUTPATH = os.path.expanduser("~")+os.sep+'.FreeCAD' # Where to store the qch file
  43. QHELPCOMPILER = 'qhelpgenerator'
  44. QCOLLECTIOMGENERATOR = 'qcollectiongenerator'
  45. PDFOUTPUT = False # if true, a pdf file will be generated instead of qhelp.
  46. REMOVE = True # if true, the temp html files are removed after successful operation
  47. PDFCONVERTOR = 'pisa' # can be 'pisa' or 'htmldoc'
  48. # END CONFIGURATION ##############################################
  49. URL = DEFAULTURL
  50. TMPFOLDER = tempfile.mkdtemp()
  51. wikiindex = "/index.php?title="
  52. processed = []
  53. pisa = None
  54. usage='''
  55. wiki2qhelp [options] [url] [index page]
  56. fetches wiki pages from the specified url, starting from specified
  57. index page, and outputs a .qch file in the specified output path.
  58. You must have qassistant installed.
  59. If no url, index page or output path is specified, the following
  60. default values will be used:
  61. url: '''+DEFAULTURL+'''
  62. index page: '''+INDEX+'''
  63. output path: '''+OUTPUTPATH+'''
  64. Options:
  65. -v: Verbose mode
  66. -c filename or --helpcompiler-exe filename: Uses filename as qt help compiler
  67. -g filename or --helpgenerator-exe filename: Uses filename as qt collection generator
  68. -o path or --out-path path: Specifies an output path
  69. -h or --help: Displays this help message
  70. -p [convertor] or --pdf [convertor]: Outputs a pdf file instead of qhelp. Convertor
  71. can be pisa (default) or htmldoc
  72. -t path or --tempfolder path: Uses path as temp folder for storing html files
  73. '''
  74. css = """/* Basic CSS for offline wiki rendering */
  75. body {
  76. font-family: Arial,Helvetica,sans-serif;
  77. font-size: 13px;
  78. text-align: justify;
  79. }
  80. h1 {
  81. font-size: 2.2em;
  82. font-weight: bold;
  83. background: #46A4D0;
  84. color: white;
  85. padding: 5px;
  86. -moz-border-radius: 5px;
  87. -webkit-border-radius: 5px;
  88. }
  89. pre {
  90. border: 1px dashed #333333;
  91. text-align: left;
  92. background: #EEEEEE;
  93. padding: 5px;
  94. }
  95. a:link, a:visited {
  96. font-weight: bold;
  97. text-decoration: none;
  98. color: #0084FF;
  99. }
  100. a:hover {
  101. text-decoration: underline;
  102. }
  103. .printfooter {
  104. font-size: 0.8em;
  105. color: #333333;
  106. border-top: 1px solid #333333;
  107. }
  108. .wikitable #toc {
  109. font-size: 0.8em;
  110. }
  111. #toc,.docnav {
  112. display: none;
  113. }
  114. """
  115. fcount = dcount = 0
  116. def rmall(dirPath): # delete dirPath and below
  117. global fcount, dcount
  118. namesHere = os.listdir(dirPath)
  119. for name in namesHere: # remove all contents first
  120. path = os.path.join(dirPath, name)
  121. if not os.path.isdir(path): # remove simple files
  122. os.remove(path)
  123. fcount = fcount + 1
  124. else: # recur to remove subdirs
  125. rmall(path)
  126. os.rmdir(dirPath) # remove now-empty dirPath
  127. dcount = dcount + 1
  128. def crawl(site=DEFAULTURL):
  129. "downloads an entire wiki site"
  130. # tests ###############################################
  131. if COMPILE and os.system(QHELPCOMPILER +' -v'):
  132. print ("Error: QAssistant not fully installed, exiting.")
  133. print (QHELPCOMPILER)
  134. return 1
  135. if COMPILE and os.system(QCOLLECTIOMGENERATOR +' -v'):
  136. print ("Error: QAssistant not fully installed, exiting.")
  137. return 1
  138. if PDFOUTPUT:
  139. if PDFCONVERTOR == 'pisa':
  140. try:
  141. import ho.pisa as pisa
  142. except: ("Error: Python-pisa not installed, exiting.")
  143. return 1
  144. else:
  145. if os.system('htmldoc --version'):
  146. print ("Error: Htmldoc not found, exiting.")
  147. return 1
  148. try:
  149. from pyPdf import PdfFileReader,PdfFileWriter
  150. except:
  151. print ("Error: Python-pypdf not installed, exiting.")
  152. # run ########################################################
  153. URL = site
  154. if VERBOSE: print ("crawling "), URL, ", saving in ", TMPFOLDER
  155. if not os.path.isdir(TMPFOLDER): os.mkdir(TMPFOLDER)
  156. file = open(TMPFOLDER + os.sep + "wiki.css",'wb')
  157. file.write(css)
  158. file.close()
  159. todolist = []
  160. count = 1
  161. indexpages = get(INDEX)
  162. todolist.extend(indexpages)
  163. while todolist:
  164. targetpage = todolist.pop()
  165. if not targetpage in NORETRIEVE:
  166. if VERBOSE: print (count, ": Fetching ", targetpage)
  167. pages = get(targetpage)
  168. count += 1
  169. processed.append(targetpage)
  170. for p in pages:
  171. if (not (p in todolist)) and (not (p in processed)):
  172. todolist.append(p)
  173. if VERBOSE: print ("Fetched ", count, " pages")
  174. if PDFOUTPUT:
  175. buildpdffiles()
  176. joinpdf()
  177. if REMOVE:
  178. if VERBOSE: print ("Deleting temp files...")
  179. rmall(TMPFOLDER)
  180. if COMPILE:
  181. qhp = buildtoc()
  182. qhcp = createCollProjectFile()
  183. if generate(qhcp) or compile(qhp):
  184. print ("Temp Folder ",TMPFOLDER," has not been deleted.")
  185. return 1
  186. else:
  187. if REMOVE:
  188. if VERBOSE: print ("Deleting temp files...")
  189. rmall(TMPFOLDER)
  190. if VERBOSE: print ("All done!")
  191. return 0
  192. def buildpdffiles(folder=TMPFOLDER,convertor=PDFCONVERTOR):
  193. "scans a folder for html files and converts them all to pdf"
  194. templist = os.listdir(folder)
  195. fileslist = []
  196. for i in templist:
  197. if i[-5:] == '.html':
  198. fileslist.append(i)
  199. for f in fileslist:
  200. if convertor == 'pisa': createpdf_pisa(f[:-5],folder)
  201. else: createpdf_htmldoc(f[:-5],folder)
  202. def fetch_resources(uri, rel):
  203. """
  204. Callback to allow pisa/reportlab to retrieve Images,Stylesheets, etc.
  205. 'uri' is the href attribute from the html link element.
  206. 'rel' gives a relative path, but it's not used here.
  207. Note from Yorik: Not working!!
  208. """
  209. path = os.path.join(TMPFOLDER,uri.replace("./", ""))
  210. return path
  211. def createpdf_pisa(pagename,folder=TMPFOLDER):
  212. "creates a pdf file from a saved page using pisa (python module)"
  213. infile = file(folder + os.sep + pagename+'.html','ro')
  214. outfile = file(folder + os.sep + pagename+'.pdf','wb')
  215. if VERBOSE: print ("Converting " + pagename + " to pdf...")
  216. pdf = pisa.CreatePDF(infile,outfile,folder,link_callback=fetch_resources)
  217. outfile.close()
  218. if pdf.err: return pdf.err
  219. return 0
  220. def createpdf_htmldoc(pagename,folder=TMPFOLDER):
  221. "creates a pdf file from a saved page using htmldoc (external app, but supports images)"
  222. infile = folder + os.sep + pagename+'.html'
  223. outfile = folder + os.sep + pagename+'.pdf'
  224. return os.system('htmldoc --webpage -f '+outfile+' '+infile)
  225. def joinpdf(folder=TMPFOLDER,startpage=INDEX,outputname='freecad.pdf'):
  226. "creates one pdf file from several others, following order from startpage"
  227. if VERBOSE: print ("Building table of contents...")
  228. f = open(folder+os.sep+startpage+'.html')
  229. html = ''
  230. for line in f: html += line
  231. f.close()
  232. html = html.replace("\n"," ")
  233. html = html.replace("> <","><")
  234. html = re.findall("<ul.*/ul>",html)[0]
  235. pages = re.findall('href="(.*?)"',html)
  236. pages.insert(1,startpage+".html")
  237. result = PdfFileWriter()
  238. for p in pages:
  239. if exists(p[:-5]):
  240. if VERBOSE: print ('Appending',p)
  241. try: inputfile = PdfFileReader(file(folder+os.sep+p[:-5]+'.pdf','rb'))
  242. except: print ('Unable to append',p)
  243. else:
  244. for i in range(inputfile.getNumPages()):
  245. result.addPage(inputfile.getPage(i))
  246. outputfile = file(OUTPUTPATH + os.sep + outputname,'wb')
  247. result.write(outputfile)
  248. outputfile.close()
  249. if VERBOSE: print ('Successfully created',OUTPUTPATH,os.sep,outputname)
  250. def compile(qhpfile,outputname='freecad.qch'):
  251. "compiles the whole html doc with qassistant"
  252. qchfile = OUTPUTPATH + os.sep + outputname
  253. if not os.system(QHELPCOMPILER + ' '+qhpfile+' -o '+qchfile):
  254. if VERBOSE: print ("Successfully created",qchfile)
  255. return 0
  256. def generate(qhcpfile):
  257. "generates qassistant-specific settings like icon, title, ..."
  258. txt="""
  259. The help files for FreeCAD.
  260. """
  261. about=open(TMPFOLDER + os.sep + "about.txt","w")
  262. about.write(txt)
  263. about.close()
  264. qhcfile = OUTPUTPATH + os.sep + "freecad.qhc"
  265. if not os.system(QCOLLECTIOMGENERATOR+' '+qhcpfile+' -o '+qhcfile):
  266. if VERBOSE: print ("Successfully created ",qhcfile)
  267. return 0
  268. def createCollProjectFile(folder=TMPFOLDER):
  269. qprojectfile = '''<?xml version="1.0" encoding="UTF-8"?>
  270. <QHelpCollectionProject version="1.0">
  271. <assistant>
  272. <title>FreeCAD User Manual</title>
  273. <applicationIcon>Crystal_Clear_app_tutorials.png</applicationIcon>
  274. <cacheDirectory>freecad/freecad</cacheDirectory>
  275. <startPage>qthelp://org.freecad.usermanual_0.9/doc/Online_Help_Startpage.html</startPage>
  276. <aboutMenuText>
  277. <text>About FreeCAD</text>
  278. </aboutMenuText>
  279. <aboutDialog>
  280. <file>about.txt</file>
  281. <!--
  282. <icon>images/icon.png</icon>
  283. -->
  284. <icon>Crystal_Clear_app_tutorials.png</icon>
  285. </aboutDialog>
  286. <enableDocumentationManager>true</enableDocumentationManager>
  287. <enableAddressBar>true</enableAddressBar>
  288. <enableFilterFunctionality>true</enableFilterFunctionality>
  289. </assistant>
  290. <docFiles>
  291. <generate>
  292. <file>
  293. <input>freecad.qhp</input>
  294. <output>freecad.qch</output>
  295. </file>
  296. </generate>
  297. <register>
  298. <file>freecad.qch</file>
  299. </register>
  300. </docFiles>
  301. </QHelpCollectionProject>
  302. '''
  303. if VERBOSE: print ("Building project file...")
  304. qfilename = folder + os.sep + "freecad.qhcp"
  305. f = open(qfilename,'w')
  306. f.write(qprojectfile)
  307. f.close()
  308. if VERBOSE: print ("Done writing qhcp file.")
  309. return qfilename
  310. def buildtoc(folder=TMPFOLDER,page=INDEX):
  311. "gets the table of contents page and parses its contents into a clean lists structure"
  312. qhelpfile = '''<?xml version="1.0" encoding="UTF-8"?>
  313. <QtHelpProject version="1.0">
  314. <namespace>org.freecad.usermanual_0.9</namespace>
  315. <virtualFolder>doc</virtualFolder>
  316. <!--
  317. <customFilter name="FreeCAD 0.10">
  318. <filterAttribute>FreeCAD</filterAttribute>
  319. <filterAttribute>0.10</filterAttribute>
  320. </customFilter>
  321. -->
  322. <filterSection>
  323. <!--
  324. <filterAttribute>FreeCAD</filterAttribute>
  325. <filterAttribute>0.10</filterAttribute>
  326. -->
  327. <toc>
  328. <inserttoc>
  329. </toc>
  330. <keywords>
  331. <insertkeywords>
  332. </keywords>
  333. <insertfiles>
  334. </filterSection>
  335. </QtHelpProject>
  336. '''
  337. def getname(line):
  338. line = re.compile('<li>').sub('',line)
  339. line = re.compile('</li>').sub('',line)
  340. title = line.strip()
  341. link = ''
  342. if "<a" in line:
  343. title = re.findall('<a[^>]*>(.*?)</a>',line)[0].strip()
  344. link = re.findall('href="(.*?)"',line)[0].strip()
  345. return title,link
  346. if VERBOSE: print ("Building table of contents...")
  347. f = open(folder+os.sep+page+'.html')
  348. html = ''
  349. for line in f: html += line
  350. f.close()
  351. html = html.replace("\n"," ")
  352. html = html.replace("> <","><")
  353. html = re.findall("<ul.*/ul>",html)[0]
  354. items = re.findall('<li[^>]*>.*?</li>|</ul></li>',html)
  355. inserttoc = '<section title="Table of Contents">\n'
  356. insertkeywords = ''
  357. for item in items:
  358. if not ("<ul>" in item):
  359. if ("</ul>" in item):
  360. inserttoc += '</section>\n'
  361. else:
  362. link = ''
  363. title,link=getname(item)
  364. if link:
  365. link='" ref="'+link
  366. insertkeywords += ('<keyword name="'+title+link+'"/>\n')
  367. inserttoc += ('<section title="'+title+link+'"></section>\n')
  368. else:
  369. subitems = item.split("<ul>")
  370. for i in range(len(subitems)):
  371. link = ''
  372. title,link=getname(subitems[i])
  373. if link:
  374. link='" ref="'+link
  375. insertkeywords += ('<keyword name="'+title+link+'"/>\n')
  376. trail = ''
  377. if i == len(subitems)-1: trail = '</section>'
  378. inserttoc += ('<section title="'+title+link+'">'+trail+'\n')
  379. inserttoc += '</section>\n'
  380. insertfiles = "<files>\n"
  381. for fil in os.listdir(folder):
  382. insertfiles += ("<file>"+fil+"</file>\n")
  383. insertfiles += "</files>\n"
  384. qhelpfile = re.compile('<insertkeywords>').sub(insertkeywords,qhelpfile)
  385. qhelpfile = re.compile('<inserttoc>').sub(inserttoc,qhelpfile)
  386. qhelpfile = re.compile('<insertfiles>').sub(insertfiles,qhelpfile)
  387. qfilename = folder + os.sep + "freecad.qhp"
  388. f = open(qfilename,'wb')
  389. f.write(qhelpfile)
  390. f.close()
  391. if VERBOSE: print ("Done writing qhp file.")
  392. return qfilename
  393. def get(page):
  394. "downloads a single page, returns the other pages it links to"
  395. html = fetchpage(page)
  396. html = cleanhtml(html)
  397. pages = getlinks(html)
  398. html = cleanlinks(html,pages)
  399. html = cleanimagelinks(html)
  400. output(html,page)
  401. return pages
  402. def cleanhtml(html):
  403. "cleans given html code from dirty script stuff"
  404. html = html.replace('\n','Wlinebreak') # removing linebreaks for regex processing
  405. html = re.compile('(.*)<div[^>]+column-content+[^>]+>').sub('',html) # stripping before content
  406. html = re.compile('<div[^>]+column-one+[^>]+>.*').sub('',html) # stripping after content
  407. html = re.compile('<!--[^>]+-->').sub('',html) # removing comment tags
  408. html = re.compile('<script[^>]*>.*?</script>').sub('',html) # removing script tags
  409. html = re.compile('<!--\[if[^>]*>.*?endif\]-->').sub('',html) # removing IE tags
  410. html = re.compile('<div id="jump-to-nav"[^>]*>.*?</div>').sub('',html) # removing nav div
  411. html = re.compile('<h3 id="siteSub"[^>]*>.*?</h3>').sub('',html) # removing print subtitle
  412. html = re.compile('Retrieved from').sub('Online version:',html) # changing online title
  413. html = re.compile('<div id="mw-normal-catlinks[^>]>.*?</div>').sub('',html) # removing catlinks
  414. html = re.compile('<div class="NavHead.*?</div>').sub('',html) # removing nav stuff
  415. html = re.compile('<div class="NavContent.*?</div>').sub('',html) # removing nav stuff
  416. html = re.compile('<div class="NavEnd.*?</div>').sub('',html) # removing nav stuff
  417. if not GETTRANSLATIONS:
  418. html = re.compile('<div class="languages.*?</div>').sub('',html) # removing translations links
  419. html = re.compile('Wlinebreak').sub('\n',html) # restoring original linebreaks
  420. return html
  421. def getlinks(html):
  422. "returns a list of wikipage links in html file"
  423. links = re.findall('<a[^>]*>.*?</a>',html)
  424. pages = []
  425. for l in links:
  426. # rg = re.findall('php\?title=(.*)\" title',l)
  427. rg = re.findall('href=.*?php\?title=(.*?)"',l)
  428. if rg:
  429. rg = rg[0]
  430. if "#" in rg:
  431. rg = rg.split('#')[0]
  432. if ":" in rg:
  433. NORETRIEVE.append(rg)
  434. if ";" in rg:
  435. NORETRIEVE.append(rg)
  436. if "&" in rg:
  437. NORETRIEVE.append(rg)
  438. if "/" in rg:
  439. if not GETTRANSLATIONS:
  440. NORETRIEVE.append(rg)
  441. pages.append(rg)
  442. return pages
  443. def getimagelinks(html):
  444. "returns a list of image links found in an html file"
  445. return re.findall('<img.*?src="(.*?)"',html)
  446. def cleanlinks(html, pages=None):
  447. "cleans page links found in html"
  448. if not pages: pages = getlinks(html)
  449. for page in pages:
  450. if page in NORETRIEVE:
  451. output = 'href="' + URL + wikiindex + page + '"'
  452. else:
  453. output = 'href="' + page.replace("/","-") + '.html"'
  454. html = re.compile('href="[^"]+' + page + '"').sub(output,html)
  455. return html
  456. def cleanimagelinks(html,links=None):
  457. "cleans image links in given html"
  458. if not links: links = getimagelinks(html)
  459. if links:
  460. for l in links:
  461. nl = re.findall('.*/(.*)',l)
  462. if nl: html = html.replace(l,nl[0])
  463. fetchimage(l)
  464. return html
  465. def fetchpage(page):
  466. "retrieves given page from the wiki"
  467. failcount = 0
  468. while failcount < MAXFAIL:
  469. try:
  470. html = (urlopen(URL + wikiindex + page).read())
  471. return html
  472. except HTTPError:
  473. failcount += 1
  474. print ('Error: unable to fetch page ' + page)
  475. def fetchimage(imagelink):
  476. "retrieves given image from the wiki and saves it"
  477. filename = re.findall('.*/(.*)',imagelink)[0]
  478. if not (filename in processed):
  479. failcount = 0
  480. while failcount < MAXFAIL:
  481. try:
  482. if VERBOSE: print ("Fetching " + filename)
  483. data = (urlopen(webroot(URL) + imagelink).read())
  484. path = local(filename,image=True)
  485. file = open(path,'wb')
  486. file.write(data)
  487. file.close()
  488. processed.append(filename)
  489. return
  490. except:
  491. failcount += 1
  492. print ('Error: unable to fetch file ' + filename)
  493. def local(page,image=False):
  494. "returns a local path for a given page/image"
  495. if image:
  496. return TMPFOLDER + os.sep + page
  497. else:
  498. return TMPFOLDER + os.sep + page + '.html'
  499. def exists(page,image=False):
  500. "checks if given page/image already exists"
  501. path = local(page,image)
  502. if os.path.exists(path): return True
  503. return False
  504. def webroot(url):
  505. return re.findall('(http://.*?)/',url)[0]
  506. def output(html,page):
  507. "encapsulates raw html code into nice html body"
  508. header = "<html><head>"
  509. header += "<title>"
  510. header += page
  511. header += "</title>"
  512. header += "<link type='text/css' href='wiki.css' rel='stylesheet'>"
  513. header += "</head><body>"
  514. footer = "</body></html>"
  515. html = header+html+footer
  516. filename = local(page.replace("/","-"))
  517. file = open(filename,'wb')
  518. file.write(html)
  519. file.close()
  520. def main(arg):
  521. global QHELPCOMPILER,QCOLLECTIOMGENERATOR,OUTPUTPATH,PDFOUTPUT,PDFCONVERTOR,TMPFOLDER
  522. try:
  523. opts, args = getopt.getopt(sys.argv[1:], "hp:t:c:g:o:", ["help", "pdf=", "noremove", "tempfolder=", "helpcompiler-exe=", "out-path=", "helpgenerator-exe="])
  524. except getopt.GetoptError:
  525. # print help information and exit:
  526. sys.stderr.write(usage)
  527. sys.exit(2)
  528. # checking on the options
  529. for o, a in opts:
  530. if o == "-v":
  531. VERBOSE = True
  532. if o in ("-p","--pdf"):
  533. PDFOUTPUT = True
  534. if a in ['pisa','htmldoc']:
  535. print ("using pdf converter:",a)
  536. PDFCONVERTOR = a
  537. if o in ("-t","--tempfolder"):
  538. print ("using tempfolder:",a)
  539. TMPFOLDER = a
  540. if o in ("-h", "--help"):
  541. sys.stderr.write(usage)
  542. sys.exit()
  543. if o in ("-c", "--helpcompiler-exe"):
  544. QHELPCOMPILER = a
  545. print ('Using: ',QHELPCOMPILER)
  546. if o in ("-g", "--helpgenerator-exe"):
  547. QCOLLECTIOMGENERATOR = a
  548. if o in ("-o", "--out-path"):
  549. print ("Using output path:",a)
  550. OUTPUTPATH = a
  551. # if arg:
  552. # if (arg[0] == '-h') or (arg[0] == '--help'):
  553. # print usage
  554. # else:
  555. # URL = arg[0]
  556. # if len(arg) > 1: INDEX = arg[1]
  557. # if len(arg) > 2: OUTPUTPATH = arg[2]
  558. # crawl()
  559. # else:
  560. crawl()
  561. if __name__ == "__main__":
  562. # main(sys.argv[1:])
  563. print "Warning! This script is obsolete. Use the scripts in the offlinedocs folder..."