Hide keyboard shortcuts

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 backup the list of modules 

4""" 

5from pyquickhelper.loghelper import get_password 

6from pyquickhelper.filehelper import TransferFTP 

7 

8 

9def ftp_list_modules(ftp_location="/home/ftpuser/ftp/web/enseignement/setup", 

10 http_location="http://www.xavierdupre.fr/enseignement/setup", 

11 filename="index_modules_list.html", 

12 ftps='SFTP'): 

13 """ 

14 Updates the list of backuped modules assuming they are stored on a FTP website. 

15 It gets the list of wheels in a folder and creates a HTML pages. 

16 It then uploads the final pages. 

17 

18 @param ftp_location location on the website 

19 @param http_location same location but on http protocol 

20 @param filename name of the file to produce 

21 @return list of modules 

22 

23 The module uses *keyring* to retrieve the credentials. 

24 You can set them up with: 

25 

26 :: 

27 

28 from pyquickhelper.loghelper import get_password 

29 get_password("ftp_list_modules", "ensae_teaching_cs2,site", "...") 

30 get_password("ftp_list_modules", "ensae_teaching_cs2,login", "...") 

31 get_password("ftp_list_modules", "ensae_teaching_cs2,password", "...") 

32 """ 

33 ftp_site = get_password( 

34 "ftp_list_modules", "ensae_teaching_cs2,site") 

35 login = get_password( 

36 "ftp_list_modules", "ensae_teaching_cs2,login") 

37 password = get_password( 

38 "ftp_list_modules", "ensae_teaching_cs2,password") 

39 

40 if not ftp_site: 

41 raise ValueError("ftp_site is empty, some missing keyring?") 

42 if not login: 

43 raise ValueError("login is empty") 

44 if not password: 

45 raise ValueError("password is empty") 

46 

47 ftp = TransferFTP(ftp_site, login, password, ftps=ftps) 

48 res = ftp.ls(ftp_location) 

49 

50 rows = ["<html><body><h1>storage for unit test</h1>\n<ul>"] 

51 ret = [] 

52 for i, v in enumerate(sorted(_["name"] for _ in res)): 

53 if v in ('.', '..'): 

54 continue 

55 ret.append(v) 

56 line = '<li>{1} - <a href="{2}/{0}">{0}</a></li>'.format( 

57 v, i, http_location) 

58 rows.append(line) 

59 rows.append("</ul></body></html>") 

60 

61 content = "\n".join(rows) 

62 bstr = content.encode('ascii') 

63 ftp.transfer(bstr, ftp_location + "/", filename) 

64 

65 ftp.close() 

66 

67 return ret