summaryrefslogtreecommitdiff
path: root/scripts/uploadrelease.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/uploadrelease.py')
-rwxr-xr-xscripts/uploadrelease.py62
1 files changed, 45 insertions, 17 deletions
diff --git a/scripts/uploadrelease.py b/scripts/uploadrelease.py
index 5b295cbb..9f6f0aee 100755
--- a/scripts/uploadrelease.py
+++ b/scripts/uploadrelease.py
@@ -5,6 +5,7 @@
from distutils.version import LooseVersion
import getopt
+import getpass
import glob
import os
from os import path
@@ -14,12 +15,15 @@ import sys
# Directories and files to exclude from release tarballs
+# for debugging, set to a local dir e.g. "localhost:/tmp/sf-adodb/"
sf_files = "frs.sourceforge.net:/home/frs/project/adodb/"
+
+# rsync command template
rsync_cmd = "rsync -vP --rsh ssh {opt} {src} {usr}@{dst}"
# Command-line options
-options = "hn"
-long_options = ["help", "dry-run"]
+options = "hu:n"
+long_options = ["help", "user=", "dry-run"]
def usage():
@@ -29,12 +33,12 @@ def usage():
current one if unspecified) to Sourceforge.
Parameters:
- username Sourceforge user account
release_path Location of the release files to upload
(see buildrelease.py)
Options:
-h | --help Show this usage message
+ -u | --user <name> Sourceforge account (defaults to current user)
-n | --dry-run Do not upload the files
''' % (
path.basename(__file__)
@@ -53,14 +57,27 @@ def call_rsync(usr, opt, src, dst):
command = rsync_cmd.format(usr=usr, opt=opt, src=src, dst=dst)
+ # Create directory if it does not exist
+ dst_split = dst.rsplit(':')
+ host = dst_split[0]
+ dst = dst_split[1]
+ mkdir = 'ssh {usr}@{host} mkdir -p {dst}'.format(
+ usr=usr,
+ host=host,
+ dst=dst
+ )
+
if dry_run:
+ print mkdir
print command
else:
+ subprocess.call(mkdir, shell=True)
subprocess.call(command, shell=True)
def get_release_version():
- ''' Get the version number from the zip file to upload
+ ''' Returns the version number (X.Y.Z) from the zip file to upload,
+ excluding the SemVer suffix
'''
try:
zipfile = glob.glob('adodb-*.zip')[0]
@@ -70,7 +87,7 @@ def get_release_version():
try:
version = re.search(
- "^adodb-([\d]+\.[\d]+\.[\d]+)\.zip$",
+ "^adodb-([\d]+\.[\d]+\.[\d]+)(-(alpha|beta|rc)\.[\d]+)?\.zip$",
zipfile
).group(1)
except AttributeError:
@@ -82,15 +99,26 @@ def get_release_version():
def sourceforge_target_dir(version):
- ''' Returns the sourceforge target directory
- Base directory as defined in sf_files global variable, plus
+ ''' Returns the sourceforge target directory, relative to the root
+ directory (defined in sf_files global variable): basedir/subdir, with
+ basedir:
+ - for ADOdb version 5: adodb-php5-only
+ - for newer versions: adodbX (where X is the major version number)
+ subdir:
- if version >= 5.21: adodb-X.Y
- for older versions: adodb-XYZ-for-php5
'''
- # Keep only X.Y (discard patch number)
- short_version = version.rsplit('.', 1)[0]
+ major_version = int(version.rsplit('.')[0])
+
+ # Base directory
+ if major_version == 5:
+ directory = 'adodb-php5-only/'
+ else:
+ directory = 'adodb{}/'.format(major_version)
+
+ # Keep only X.Y (discard patch number and pre-release suffix)
+ short_version = version.split('-')[0].rsplit('.', 1)[0]
- directory = 'adodb-php5-only/'
if LooseVersion(version) >= LooseVersion('5.21'):
directory += "adodb-" + short_version
else:
@@ -112,12 +140,9 @@ def process_command_line():
usage()
sys.exit(2)
- if len(args) < 1:
- usage()
- print "ERROR: please specify the Sourceforge user and release_path"
- sys.exit(1)
-
# Default values for flags
+ username = getpass.getuser()
+ print username
dry_run = False
for opt, val in opts:
@@ -125,15 +150,18 @@ def process_command_line():
usage()
sys.exit(0)
+ elif opt in ("-u", "--user"):
+ username = val
+
elif opt in ("-n", "--dry-run"):
dry_run = True
# Mandatory parameters
- username = args[0]
+ # (none)
# Change to release directory, current if not specified
try:
- release_path = args[1]
+ release_path = args[0]
os.chdir(release_path)
except IndexError:
release_path = os.getcwd()