Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief Various functions to install `Putty <http://www.putty.org/>`_.
4"""
5from __future__ import print_function
6import sys
7import re
8import os
10from .install_custom import download_page, download_file
12if sys.version_info[0] == 2:
13 FileNotFoundError = Exception
16def IsPuttyInstalled(dest_folder):
17 """
18 check if Scite was already installed
20 @param dest_folder where it was installed
21 @return boolean
22 """
23 if sys.platform.startswith("win"):
24 file = os.path.join(dest_folder, "putty.exe")
25 return os.path.exists(file)
26 else:
27 raise NotImplementedError("not available on platform " + sys.platform)
30def install_putty(dest_folder=".", fLOG=print, install=True, version=None):
31 """
32 install `Putty <http://www.putty.org/>`_ (only on Windows)
34 @param dest_folder where to download putty
35 @param fLOG logging function
36 @param install install (otherwise only download)
37 @param version version to install (unused)
38 @return temporary file
39 """
40 if version is not None:
41 raise ValueError("cannot specify a version")
42 if IsPuttyInstalled(dest_folder):
43 return os.path.join(
44 os.path.abspath(dest_folder), "putty.exe")
46 if not sys.platform.startswith("win"):
47 raise NotImplementedError(
48 "SciTE can only be installed on Windows at the moment")
50 url = "http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html"
51 page = download_page(url)
53 reg = re.compile(
54 "<a href=\\\"(.*latest/w64/putty.exe)\\\"><code>putty.exe</code></a>")
55 find = reg.findall(page)
56 if len(find) != 1:
57 mes = "unable to find the file to download at {0}\nfound: {1}\npattern: {2}\nOUT:\n{3}".format(
58 url, len(find), reg.pattern, "\n".join(find))
59 raise Exception(mes)
61 # should be something like http://www.scintilla.org/wscite356.zip
62 newurl = find[0]
63 outfile = os.path.join(dest_folder, "putty.exe")
64 if not os.path.exists(outfile):
65 try:
66 download_file(newurl, outfile)
67 except Exception as e:
68 raise Exception("unable to download\n{0}\nto{1}".format(
69 newurl, outfile)) from e
71 if not os.path.exists(outfile):
72 raise FileNotFoundError(outfile)
74 return outfile