Skip to content

Commit

Permalink
Allow the user to specify FTP credentials per branch
Browse files Browse the repository at this point in the history
The ftpdata file format has changed: each section is named [branch]
instead of [ftp].
There is no way to obtain the previous behavior with this
implementation: each branch has to have a section in the ftpdata file,
otherwise, the user will be asked for the credential through stdin
  • Loading branch information
nviennot committed Nov 16, 2010
1 parent 6161723 commit 2839107
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
11 changes: 9 additions & 2 deletions README
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,12 +12,19 @@ Usage: python git-ftp.py


You can place FTP credentials in .git/ftpdata, as such: You can place FTP credentials in .git/ftpdata, as such:


[ftp] [master]
username=me username=me
password=s00perP4zzw0rd password=s00perP4zzw0rd
hostname=ftp.hostname.com hostname=ftp.hostname.com
remotepath=/htdocs remotepath=/htdocs
repository=/home/me/website
[staging]
username=me
password=s00perP4zzw0rd
hostname=ftp.hostname.com
remotepath=/htdocs/staging

Each section corresponds to a git branch.


License: License:


Expand Down
23 changes: 15 additions & 8 deletions git-ftp.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
class BranchNotFound(Exception): class BranchNotFound(Exception):
pass pass


class FtpDataOldVersion(Exception):
pass

def main(): def main():
Git.git_binary = 'git' # Windows doesn't like env Git.git_binary = 'git' # Windows doesn't like env


Expand Down Expand Up @@ -131,14 +134,13 @@ def get_ftp_creds(repo, options):
Retrieves the data to connect to the FTP from .git/ftpdata Retrieves the data to connect to the FTP from .git/ftpdata
or interactively. or interactively.
ftpdata format example:: ftpdata format example:
[ftp] [branch]
username=me username=me
password=s00perP4zzw0rd password=s00perP4zzw0rd
hostname=ftp.hostname.com hostname=ftp.hostname.com
remotepath=/htdocs remotepath=/htdocs
repository=/home/me/website
Please note that it isn't necessary to have this file, Please note that it isn't necessary to have this file,
you'll be asked for the data every time you upload something. you'll be asked for the data every time you upload something.
Expand All @@ -151,14 +153,19 @@ def get_ftp_creds(repo, options):
cfg = ConfigParser.ConfigParser() cfg = ConfigParser.ConfigParser()
cfg.read(ftpdata) cfg.read(ftpdata)


if (not cfg.has_section(options.branch)) and cfg.has_section('ftp'):
raise FtpDataOldVersion("Please rename the [ftp] section to [branch]. " +
"Take a look at the README for more information")

# just in case you do not want to store your ftp password. # just in case you do not want to store your ftp password.
try: try:
options.ftp.password = cfg.get('ftp','password') options.ftp.password = cfg.get(options.branch,'password')
except: except ConfigParser.NoOptionError:
options.ftp.password = getpass.getpass('FTP Password: ') options.ftp.password = getpass.getpass('FTP Password: ')
options.ftp.username = cfg.get('ftp','username')
options.ftp.hostname = cfg.get('ftp','hostname') options.ftp.username = cfg.get(options.branch,'username')
options.ftp.remotepath = cfg.get('ftp','remotepath') options.ftp.hostname = cfg.get(options.branch,'hostname')
options.ftp.remotepath = cfg.get(options.branch,'remotepath')
else: else:
options.ftp.username = raw_input('FTP Username: ') options.ftp.username = raw_input('FTP Username: ')
options.ftp.password = getpass.getpass('FTP Password: ') options.ftp.password = getpass.getpass('FTP Password: ')
Expand Down

0 comments on commit 2839107

Please sign in to comment.