3 ADOdb release upload script
6 from distutils
.version
import LooseVersion
16 # Directories and files to exclude from release tarballs
17 sf_files
= "frs.sourceforge.net:/home/frs/project/adodb/"
18 rsync_cmd
= "rsync -vP --rsh ssh {opt} {src} {usr}@{dst}"
20 # Command-line options
22 long_options
= ["help", "dry-run"]
26 print '''Usage: %s [options] username [release_path]
28 This script will upload the files in the given directory (or the
29 current one if unspecified) to Sourceforge.
32 username Sourceforge user account
33 release_path Location of the release files to upload
37 -h | --help Show this usage message
38 -n | --dry-run Do not upload the files
40 path
.basename(__file__
)
45 def call_rsync(usr
, opt
, src
, dst
):
46 ''' Calls rsync to upload files with given parameters
49 src = source directory
50 dst = target directory
54 command
= rsync_cmd
.format(usr
=usr
, opt
=opt
, src
=src
, dst
=dst
)
59 subprocess
.call(command
, shell
=True)
62 def get_release_version():
63 ''' Get the version number from the zip file to upload
66 zipfile
= glob
.glob('adodb-*.zip')[0]
68 print "ERROR: release zip file not found in '%s'" % release_path
73 "^adodb-([\d]+\.[\d]+\.[\d]+)\.zip$",
76 except AttributeError:
77 print "ERROR: unable to extract version number from '%s'" % zipfile
78 print " Only 3 groups of digits separated by periods are allowed"
84 def sourceforge_target_dir(version
):
85 ''' Returns the sourceforge target directory
86 Base directory as defined in sf_files global variable, plus
87 - if version >= 5.21: adodb-X.Y
88 - for older versions: adodb-XYZ-for-php5
90 # Keep only X.Y (discard patch number)
91 short_version
= version
.rsplit('.', 1)[0]
93 directory
= 'adodb-php5-only/'
94 if LooseVersion(version
) >= LooseVersion('5.21'):
95 directory
+= "adodb-" + short_version
97 directory
+= "adodb-{}-for-php5".format(short_version
.replace('.', ''))
102 def process_command_line():
103 ''' Retrieve command-line options and set global variables accordingly
105 global upload_files
, upload_doc
, dry_run
, username
, release_path
107 # Get command-line options
109 opts
, args
= getopt
.gnu_getopt(sys
.argv
[1:], options
, long_options
)
110 except getopt
.GetoptError
, err
:
117 print "ERROR: please specify the Sourceforge user and release_path"
120 # Default values for flags
123 for opt
, val
in opts
:
124 if opt
in ("-h", "--help"):
128 elif opt
in ("-n", "--dry-run"):
131 # Mandatory parameters
134 # Change to release directory, current if not specified
136 release_path
= args
[1]
137 os
.chdir(release_path
)
139 release_path
= os
.getcwd()
142 def upload_release_files():
143 ''' Upload release files from source directory to SourceForge
145 version
= get_release_version()
146 target
= sf_files
+ sourceforge_target_dir(version
)
149 print "Uploading release files..."
150 print " Source:", release_path
151 print " Target: " + target
156 path
.join(release_path
, "*"),
162 process_command_line()
164 # Start upload process
165 print "ADOdb release upload script"
167 upload_release_files()
171 if __name__
== "__main__":