def ftp_list_modules( ftp_location="/www/htdocs/enseignement/setup", http_location="http://www.xavierdupre.fr/enseignement/setup", filename="index_modules_list.html"): """ Update the list of backuped modules assuming they are stored on a FTP website. It gets the list of wheels in a folder and creates a HTML pages. It then uploads the final pages @param ftp_location location on the website @param http_location same location but on http protocol @param filename name of the file to produce @return list of modules The module uses *keyring* to retrieve the credentials. You can set them up with: :: keyring.get_password("ftp_list_modules", os.environ["COMPUTERNAME"] + "site", "...") keyring.get_password("ftp_list_modules", os.environ["COMPUTERNAME"] + "login", "...") keyring.get_password("ftp_list_modules", os.environ["COMPUTERNAME"] + "password", "...") """ hostname = os.environ.get("COMPUTERNAME", os.environ.get("HOSTNAME", "")) with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring ftp_site = keyring.get_password("ftp_list_modules", hostname + "site") login = keyring.get_password("ftp_list_modules", hostname + "login") password = keyring.get_password("ftp_list_modules", hostname + "password") if not ftp_site: raise ValueError("ftp_site is empty, some missing keyring?") if not login: raise ValueError("login is empty") if not password: raise ValueError("password is empty") ftp = TransferFTP(ftp_site, login, password) res = ftp.ls(ftp_location) rows = ["<html><body><h1>storage for unit test</h1>\n<ul>"] ret = [] for i, v in enumerate(sorted(_["name"] for _ in res)): if v in ('.', '..'): continue ret.append(v) line = '<li>{1} - <a href="{2}/{0}">{0}</a></li>'.format( v, i, http_location) rows.append(line) rows.append("</ul></body></html>") content = "\n".join(rows) bstr = content.encode('ascii') ftp.transfer(bstr, ftp_location + "/", filename) ftp.close() return ret
def test_transfer_ftp_true(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring prefix = "pyquickhelper," try: user = keyring.get_password("web", prefix + "user") pwd = keyring.get_password("web", prefix + "pwd") except RuntimeError: user = None pwd = None if user is None: if not is_travis_or_appveyor(): zoo = [] for k, v in sorted(os.environ.items()): zoo.append("{0}={1}".format(k, v)) raise Exception("user password is empty, prefix='{0}', username='******'\n{2}".format( prefix, get_user(), "\n".join(zoo))) return web = TransferFTP("ftp.xavierdupre.fr", user, pwd, fLOG=fLOG) r = web.ls(".") fLOG(r) self.assertTrue(isinstance(r, list)) web.close()
def ftp_list_modules(ftp_location="/www/htdocs/enseignement/setup", http_location="http://www.xavierdupre.fr/enseignement/setup", filename="index_modules_list.html"): """ Updates the list of backuped modules assuming they are stored on a FTP website. It gets the list of wheels in a folder and creates a HTML pages. It then uploads the final pages. @param ftp_location location on the website @param http_location same location but on http protocol @param filename name of the file to produce @return list of modules The module uses *keyring* to retrieve the credentials. You can set them up with: :: keyring.get_password("ftp_list_modules", "ensae_teaching_cs,site", "...") keyring.get_password("ftp_list_modules", "ensae_teaching_cs,login", "...") keyring.get_password("ftp_list_modules", "ensae_teaching_cs,password", "...") """ with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring ftp_site = keyring.get_password( "ftp_list_modules", "ensae_teaching_cs,site") login = keyring.get_password("ftp_list_modules", "ensae_teaching_cs,login") password = keyring.get_password( "ftp_list_modules", "ensae_teaching_cs,password") if not ftp_site: raise ValueError("ftp_site is empty, some missing keyring?") if not login: raise ValueError("login is empty") if not password: raise ValueError("password is empty") ftp = TransferFTP(ftp_site, login, password) res = ftp.ls(ftp_location) rows = ["<html><body><h1>storage for unit test</h1>\n<ul>"] ret = [] for i, v in enumerate(sorted(_["name"] for _ in res)): if v in ('.', '..'): continue ret.append(v) line = '<li>{1} - <a href="{2}/{0}">{0}</a></li>'.format( v, i, http_location) rows.append(line) rows.append("</ul></body></html>") content = "\n".join(rows) bstr = content.encode('ascii') ftp.transfer(bstr, ftp_location + "/", filename) ftp.close() return ret
def ftp_list_modules(ftp_location="/home/ftpuser/ftp/web/enseignement/setup", http_location="http://www.xavierdupre.fr/enseignement/setup", filename="index_modules_list.html", ftps='SFTP'): """ Updates the list of backuped modules assuming they are stored on a FTP website. It gets the list of wheels in a folder and creates a HTML pages. It then uploads the final pages. @param ftp_location location on the website @param http_location same location but on http protocol @param filename name of the file to produce @return list of modules The module uses *keyring* to retrieve the credentials. You can set them up with: :: from pyquickhelper.loghelper import get_password get_password("ftp_list_modules", "ensae_teaching_cs2,site", "...") get_password("ftp_list_modules", "ensae_teaching_cs2,login", "...") get_password("ftp_list_modules", "ensae_teaching_cs2,password", "...") """ ftp_site = get_password( "ftp_list_modules", "ensae_teaching_cs2,site") login = get_password( "ftp_list_modules", "ensae_teaching_cs2,login") password = get_password( "ftp_list_modules", "ensae_teaching_cs2,password") if not ftp_site: raise ValueError("ftp_site is empty, some missing keyring?") if not login: raise ValueError("login is empty") if not password: raise ValueError("password is empty") ftp = TransferFTP(ftp_site, login, password, ftps=ftps) res = ftp.ls(ftp_location) rows = ["<html><body><h1>storage for unit test</h1>\n<ul>"] ret = [] for i, v in enumerate(sorted(_["name"] for _ in res)): if v in ('.', '..'): continue ret.append(v) line = '<li>{1} - <a href="{2}/{0}">{0}</a></li>'.format( v, i, http_location) rows.append(line) rows.append("</ul></body></html>") content = "\n".join(rows) bstr = content.encode('ascii') ftp.transfer(bstr, ftp_location + "/", filename) ftp.close() return ret
def test_transfer_ftp_true(self): fLOG(__file__, self._testMethodName, OutputPrint=__name__ == "__main__") prefix = "pyquickhelper," try: user = get_password("web", prefix + "user", ask=False) pwd = get_password("web", prefix + "pwd", ask=False) ftpsite = get_password("web", prefix + "ftp", ask=False) except (RuntimeError, AttributeError): user = None pwd = None if user is None: if not is_travis_or_appveyor(): zoo = [] for k, v in sorted(os.environ.items()): zoo.append("{0}={1}".format(k, v)) raise Exception( "user password is empty, prefix='{0}', username='******'\n{2}" .format(prefix, get_user(), "\n".join(zoo))) return try: web = TransferFTP(ftpsite, user, pwd, fLOG=fLOG) except ftplib.error_perm as e: if "Non-anonymous sessions must use encryption." in str(e): return raise e except ftplib.error_temp as e: if "421 Home directory not available" in str(e): return raise e except socket.gaierror as ee: if "Name or service not known" in str(ee): return if "getaddrinfo failed" in str(ee): return raise ee r = web.ls(".") fLOG(r) self.assertTrue(isinstance(r, list)) web.close()
def test_transfer_ftp_true(self): fLOG( __file__, self._testMethodName, OutputPrint=__name__ == "__main__") with warnings.catch_warnings(): warnings.simplefilter('ignore', DeprecationWarning) import keyring prefix = "pyquickhelper," try: user = keyring.get_password("web", prefix + "user") pwd = keyring.get_password("web", prefix + "pwd") ftpsite = keyring.get_password("web", prefix + "ftp") except RuntimeError: user = None pwd = None if user is None: if not is_travis_or_appveyor(): zoo = [] for k, v in sorted(os.environ.items()): zoo.append("{0}={1}".format(k, v)) raise Exception("user password is empty, prefix='{0}', username='******'\n{2}".format( prefix, get_user(), "\n".join(zoo))) return try: web = TransferFTP(ftpsite, user, pwd, fLOG=fLOG) except ftplib.error_temp as e: if "421 Home directory not available" in str(e): return raise e except socket.gaierror as ee: if "Name or service not known" in str(ee): return if "getaddrinfo failed" in str(ee): return raise ee r = web.ls(".") fLOG(r) self.assertTrue(isinstance(r, list)) web.close()