Skip to content

Added support for '--dry-run' #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions git-ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,52 @@

from git import Blob, Repo, Git, Submodule

class FTPDryRun(object):
def mkd(self, pathname):
print "[FTP] Create directory %s" % pathname

def storbinary(self, command, file, blocksize = None, callback = None, rest = None):
print "[FTP] Create file %s" % command.split()[1]

def storlines(self, command, file, callback = None):
print "[FTP] Create file %s" % command.split()[1]

def delete(self, filename):
print "[FTP] Delete file %s" % filename

def rmd(self, dirname):
print "[FTP] Delete directory %s" % dirname

def rename(self, fromname, toname):
print "[FTP] Rename %s to %s" % (fromname, toname)

class FTP(FTPDryRun, ftplib.FTP):
def __init__(self, host = None, user = None, passwd = None, acct = None, timeout = None):
ftplib.FTP.__init__(self, host, user, passwd, acct, timeout)

def voidcmd(self, command):
if command.startswith("SITE CHMOD "):
print "[FTP] Change permission '%s'" % command
else:
super(FTP, self).voidcmd(command)

def cwd(self, pathname):
super(FTP, self).cwd(pathname)
print "[FTP] Change directory '%s'" % pathname

class FTP_TLS(ftplib.FTP_TLS, FTPDryRun):
def __init__(self, host = None, user = None, passwd = None, acct = None, keyfile = None, certfile = None, context = None, timeout = None):
ftplib.FTP_TLS.__init__(self, host, user, passwd, acct, keyfile, certfile, context, timeout)

def voidcmd(self, command):
if command.startswith("SITE CHMOD "):
print "[FTP] Change permission '%s'" % command
else:
super(FTP_TLS, self).voidcmd(command)

def cwd(self, pathname):
super(FTP_TLS, self).cwd(pathname)
print "[FTP] Change directory '%s'" % pathname

class BranchNotFound(Exception):
pass
Expand Down Expand Up @@ -138,13 +184,19 @@ def main():
tree = commit.tree
if options.ftp.ssl:
if hasattr(ftplib, 'FTP_TLS'): # SSL new in 2.7+
ftp = ftplib.FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password)
if options.dry_run:
ftp = FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password)
else:
ftp = ftplib.FTP_TLS(options.ftp.hostname, options.ftp.username, options.ftp.password)
ftp.prot_p()
logging.info("Using SSL")
else:
raise FtpSslNotSupported("Python is too old for FTP SSL. Try using Python 2.7 or later.")
else:
ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password)
if options.dry_run:
ftp = FTP(options.ftp.hostname, options.ftp.username, options.ftp.password)
else:
ftp = ftplib.FTP(options.ftp.hostname, options.ftp.username, options.ftp.password)
ftp.cwd(base)

# Check revision
Expand Down Expand Up @@ -211,6 +263,8 @@ def parse_args():
help="use this commit instead of HEAD")
parser.add_option('-s', '--section', dest="section", default=None,
help="use this section from ftpdata instead of branch name")
parser.add_option('-d', '--dry-run', dest="dry_run", action="store_true", default=False,
help="use this option to simulate what the script would do")
options, args = parser.parse_args()
configure_logging(options)
if len(args) > 1:
Expand Down