|
56 | 56 |
|
57 | 57 | from git import Blob, Repo, Git, Submodule |
58 | 58 |
|
| 59 | +class FTPDryRun(object): |
| 60 | + def mkd(self, pathname): |
| 61 | + print "[FTP] Create directory %s" % pathname |
| 62 | + |
| 63 | + def storbinary(self, command, file, blocksize = None, callback = None, rest = None): |
| 64 | + print "[FTP] Create file %s" % command.split()[1] |
| 65 | + |
| 66 | + def storlines(self, command, file, callback = None): |
| 67 | + print "[FTP] Create file %s" % command.split()[1] |
| 68 | + |
| 69 | + def delete(self, filename): |
| 70 | + print "[FTP] Delete file %s" % filename |
| 71 | + |
| 72 | + def rmd(self, dirname): |
| 73 | + print "[FTP] Delete directory %s" % dirname |
| 74 | + |
| 75 | + def rename(self, fromname, toname): |
| 76 | + print "[FTP] Rename %s to %s" % (fromname, toname) |
| 77 | + |
| 78 | +class FTP(FTPDryRun, ftplib.FTP): |
| 79 | + def __init__(self, host = None, user = None, passwd = None, acct = None, timeout = None): |
| 80 | + ftplib.FTP.__init__(self, host, user, passwd, acct, timeout) |
| 81 | + |
| 82 | + def voidcmd(self, command): |
| 83 | + if command.startswith("SITE CHMOD "): |
| 84 | + print "[FTP] Change permission '%s'" % command |
| 85 | + else: |
| 86 | + super(FTP, self).voidcmd(command) |
| 87 | + |
| 88 | + def cwd(self, pathname): |
| 89 | + super(FTP, self).cwd(pathname) |
| 90 | + print "[FTP] Change directory '%s'" % pathname |
| 91 | + |
| 92 | +class FTP_TLS(ftplib.FTP_TLS, FTPDryRun): |
| 93 | + def __init__(self, host = None, user = None, passwd = None, acct = None, keyfile = None, certfile = None, context = None, timeout = None): |
| 94 | + ftplib.FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, context, timeout) |
| 95 | + |
| 96 | + def voidcmd(self, command): |
| 97 | + if command.startswith("SITE CHMOD "): |
| 98 | + print "[FTP] Change permission '%s'" % command |
| 99 | + else: |
| 100 | + super(FTP_TLS, self).voidcmd(command) |
| 101 | + |
| 102 | + def cwd(self, pathname): |
| 103 | + super(FTP_TLS, self).cwd(pathname) |
| 104 | + print "[FTP] Change directory '%s'" % pathname |
59 | 105 |
|
60 | 106 | class BranchNotFound(Exception): |
61 | 107 | pass |
@@ -138,13 +184,19 @@ def main(): |
138 | 184 | tree = commit.tree |
139 | 185 | if options.ftp.ssl: |
140 | 186 | if hasattr(ftplib, 'FTP_TLS'): # SSL new in 2.7+ |
141 | | - ftp = ftplib.FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password) |
| 187 | + if options.dry_run: |
| 188 | + ftp = FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password) |
| 189 | + else: |
| 190 | + ftp = ftplib.FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password) |
142 | 191 | ftp.prot_p() |
143 | 192 | logging.info("Using SSL") |
144 | 193 | else: |
145 | 194 | raise FtpSslNotSupported("Python is too old for FTP SSL. Try using Python 2.7 or later.") |
146 | 195 | else: |
147 | | - ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password) |
| 196 | + if options.dry_run: |
| 197 | + ftp = FTP(options.ftp.hostname, options.ftp.username, options.ftp.password) |
| 198 | + else: |
| 199 | + ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password) |
148 | 200 | ftp.cwd(base) |
149 | 201 |
|
150 | 202 | # Check revision |
@@ -211,6 +263,8 @@ def parse_args(): |
211 | 263 | help="use this commit instead of HEAD") |
212 | 264 | parser.add_option('-s', '--section', dest="section", default=None, |
213 | 265 | help="use this section from ftpdata instead of branch name") |
| 266 | + parser.add_option('-d', '--dry-run', dest="dry_run", action="store_true", default=False, |
| 267 | + help="use this option to simulate what the script would do") |
214 | 268 | options, args = parser.parse_args() |
215 | 269 | configure_logging(options) |
216 | 270 | if len(args) > 1: |
|
0 commit comments