updated adodb package to work with php 7.1
[openemr.git] / vendor / adodb / adodb-php / scripts / uploadrelease.py
blob5b295cbbb7335f9cf268f84eafa240bc3b6e4123
1 #!/usr/bin/python -u
2 '''
3 ADOdb release upload script
4 '''
6 from distutils.version import LooseVersion
7 import getopt
8 import glob
9 import os
10 from os import path
11 import re
12 import subprocess
13 import sys
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
21 options = "hn"
22 long_options = ["help", "dry-run"]
25 def usage():
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.
31 Parameters:
32 username Sourceforge user account
33 release_path Location of the release files to upload
34 (see buildrelease.py)
36 Options:
37 -h | --help Show this usage message
38 -n | --dry-run Do not upload the files
39 ''' % (
40 path.basename(__file__)
42 #end usage()
45 def call_rsync(usr, opt, src, dst):
46 ''' Calls rsync to upload files with given parameters
47 usr = ssh username
48 opt = options
49 src = source directory
50 dst = target directory
51 '''
52 global dry_run
54 command = rsync_cmd.format(usr=usr, opt=opt, src=src, dst=dst)
56 if dry_run:
57 print command
58 else:
59 subprocess.call(command, shell=True)
62 def get_release_version():
63 ''' Get the version number from the zip file to upload
64 '''
65 try:
66 zipfile = glob.glob('adodb-*.zip')[0]
67 except IndexError:
68 print "ERROR: release zip file not found in '%s'" % release_path
69 sys.exit(1)
71 try:
72 version = re.search(
73 "^adodb-([\d]+\.[\d]+\.[\d]+)\.zip$",
74 zipfile
75 ).group(1)
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"
79 sys.exit(1)
81 return version
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
89 '''
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
96 else:
97 directory += "adodb-{}-for-php5".format(short_version.replace('.', ''))
99 return directory
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
108 try:
109 opts, args = getopt.gnu_getopt(sys.argv[1:], options, long_options)
110 except getopt.GetoptError, err:
111 print str(err)
112 usage()
113 sys.exit(2)
115 if len(args) < 1:
116 usage()
117 print "ERROR: please specify the Sourceforge user and release_path"
118 sys.exit(1)
120 # Default values for flags
121 dry_run = False
123 for opt, val in opts:
124 if opt in ("-h", "--help"):
125 usage()
126 sys.exit(0)
128 elif opt in ("-n", "--dry-run"):
129 dry_run = True
131 # Mandatory parameters
132 username = args[0]
134 # Change to release directory, current if not specified
135 try:
136 release_path = args[1]
137 os.chdir(release_path)
138 except IndexError:
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)
148 print
149 print "Uploading release files..."
150 print " Source:", release_path
151 print " Target: " + target
152 print
153 call_rsync(
154 username,
156 path.join(release_path, "*"),
157 target
161 def main():
162 process_command_line()
164 # Start upload process
165 print "ADOdb release upload script"
167 upload_release_files()
169 #end main()
171 if __name__ == "__main__":
172 main()