| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
# |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
HOST = 'ftpperso.free.fr' |
| 27 |
REMOTE_PATH = '/doc/html' |
| 28 |
|
| 29 |
from os import listdir |
| 30 |
from os.path import join, split, realpath, isdir, isfile |
| 31 |
import sys |
| 32 |
import subprocess |
| 33 |
from ftplib import FTP, error_perm |
| 34 |
|
| 35 |
_module_path = split(realpath(sys._getframe().f_code.co_filename))[0] |
| 36 |
|
| 37 |
LOCAL_PATH = realpath(join(_module_path + '/../wxgeometrie/doc/html')) |
| 38 |
|
| 39 |
command = ('cd ' + _module_path + '/../doc;make clean;make html;' |
| 40 |
+ 'rm -rf ../wxgeometrie/doc/html/*;' |
| 41 |
+ 'cp -rf ../build/html/* ../wxgeometrie/doc/html;' |
| 42 |
) |
| 43 |
subprocess.call(command, shell=True) |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
class MyFTP(FTP): |
| 51 |
"""FTP avec une interface de plus haut niveau.""" |
| 52 |
|
| 53 |
def is_rdir(self, name): |
| 54 |
"Indique s'il s'agit ou non d'un répertoire distant." |
| 55 |
try: |
| 56 |
self.cwd(name) |
| 57 |
self.cwd('..') |
| 58 |
return True |
| 59 |
except error_perm: |
| 60 |
return False |
| 61 |
|
| 62 |
def remove_r(self, rpath): |
| 63 |
"Efface un fichier ou un répertoire, même non vide." |
| 64 |
if self.is_rdir(rpath): |
| 65 |
for pth in self.nlst(rpath)[2:]: |
| 66 |
self.remove_r(pth) |
| 67 |
print('* %s : %s ' % (rpath, self.rmd(rpath))) |
| 68 |
else: |
| 69 |
print('* %s : %s ' % (rpath, self.delete(rpath))) |
| 70 |
|
| 71 |
|
| 72 |
def copy_r(self, lpath, rdest): |
| 73 |
"""Copie récursivement un répertoire local à l'emplacement distant indiqué. |
| 74 |
|
| 75 |
L'emplacement distant est créé lors de la copie, et ne doit pas exister |
| 76 |
au préalable (contrairement au `cp -r` de UNIX). |
| 77 |
""" |
| 78 |
if isdir(lpath): |
| 79 |
print("\033[32m%s\033[0m" % self.mkd(rdest)) |
| 80 |
for pth in listdir(lpath): |
| 81 |
self.copy_r(join(lpath, pth), join(rdest, pth)) |
| 82 |
else: |
| 83 |
with open(lpath, 'rb') as _file: |
| 84 |
print('* %s : %s ' |
| 85 |
% (rdest, self.storbinary('STOR ' + rdest, _file))) |
| 86 |
|
| 87 |
|
| 88 |
def miroir(self, lpath, rdest): |
| 89 |
"""Crée un clône du répertoire local à l'emplacement distant. |
| 90 |
|
| 91 |
Si l'emplacement distant existe déjà, il est supprimé au préalable.""" |
| 92 |
if self.is_rdir(rdest): |
| 93 |
self.remove_r(rdest) |
| 94 |
self.copy_r(lpath, rdest) |
| 95 |
|
| 96 |
FTPCONFIG = join(_module_path, '.ftpconfig') |
| 97 |
|
| 98 |
if isfile(FTPCONFIG): |
| 99 |
with open(FTPCONFIG) as _file: |
| 100 |
LOGIN, PASSWORD = _file.read(1000).split() |
| 101 |
else: |
| 102 |
LOGIN = input('login:') |
| 103 |
PASSWORD = input('password:') |
| 104 |
|
| 105 |
ftp = MyFTP(HOST) |
| 106 |
|
| 107 |
while LOGIN or PASSWORD: |
| 108 |
try: |
| 109 |
ftp.login(LOGIN, PASSWORD) |
| 110 |
ftp.set_pasv(True) |
| 111 |
break |
| 112 |
except error_perm: |
| 113 |
print('\n*** Login incorrect. ***\n') |
| 114 |
LOGIN = input('login:') |
| 115 |
PASSWORD = input('password:') |
| 116 |
|
| 117 |
ftp.miroir(LOCAL_PATH, REMOTE_PATH) |
| 118 |
ftp.quit() |
| 119 |
print('\n\033[32mLa doc a été mise à jour avec succès !\033[0m\n') |