Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow the user to specify FTP credentials per branch

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...
commit 28391076466f12bb5dd4c29c138ab61295883f3b 1 parent 6161723
@nviennot nviennot authored
Showing with 24 additions and 10 deletions.
  1. +9 −2 README
  2. +15 −8 git-ftp.py
View
11 README
@@ -12,12 +12,19 @@ Usage: python git-ftp.py
You can place FTP credentials in .git/ftpdata, as such:
-[ftp]
+[master]
username=me
password=s00perP4zzw0rd
hostname=ftp.hostname.com
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:
View
23 git-ftp.py
@@ -43,6 +43,9 @@
class BranchNotFound(Exception):
pass
+class FtpDataOldVersion(Exception):
+ pass
+
def main():
Git.git_binary = 'git' # Windows doesn't like env
@@ -131,14 +134,13 @@ def get_ftp_creds(repo, options):
Retrieves the data to connect to the FTP from .git/ftpdata
or interactively.
- ftpdata format example::
+ ftpdata format example:
- [ftp]
+ [branch]
username=me
password=s00perP4zzw0rd
hostname=ftp.hostname.com
remotepath=/htdocs
- repository=/home/me/website
Please note that it isn't necessary to have this file,
you'll be asked for the data every time you upload something.
@@ -151,14 +153,19 @@ def get_ftp_creds(repo, options):
cfg = ConfigParser.ConfigParser()
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.
try:
- options.ftp.password = cfg.get('ftp','password')
- except:
+ options.ftp.password = cfg.get(options.branch,'password')
+ except ConfigParser.NoOptionError:
options.ftp.password = getpass.getpass('FTP Password: ')
- options.ftp.username = cfg.get('ftp','username')
- options.ftp.hostname = cfg.get('ftp','hostname')
- options.ftp.remotepath = cfg.get('ftp','remotepath')
+
+ options.ftp.username = cfg.get(options.branch,'username')
+ options.ftp.hostname = cfg.get(options.branch,'hostname')
+ options.ftp.remotepath = cfg.get(options.branch,'remotepath')
else:
options.ftp.username = raw_input('FTP Username: ')
options.ftp.password = getpass.getpass('FTP Password: ')
Please sign in to comment.
Something went wrong with that request. Please try again.