summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/buildrelease.py2
-rw-r--r--scripts/fix-static-docs.php221
-rwxr-xr-xscripts/uploadrelease.py62
3 files changed, 267 insertions, 18 deletions
diff --git a/scripts/buildrelease.py b/scripts/buildrelease.py
index 0b37b97b..6930d169 100755
--- a/scripts/buildrelease.py
+++ b/scripts/buildrelease.py
@@ -41,7 +41,7 @@ exclude_list = (".git*",
# Command-line options
options = "hb:dfk"
-long_options = ["help", "branch", "debug", "fresh", "keep"]
+long_options = ["help", "branch=", "debug", "fresh", "keep"]
# Global flags
debug_mode = False
diff --git a/scripts/fix-static-docs.php b/scripts/fix-static-docs.php
new file mode 100644
index 00000000..32133e02
--- /dev/null
+++ b/scripts/fix-static-docs.php
@@ -0,0 +1,221 @@
+<?php
+/**
+* A Program to post-process the dokuwiki document export to clean it up
+* and fix the broken links
+*
+* @link http://adodb.org/dokuwiki/doku.php?id=v6:offline_docs_build
+* @author Mark Newnham
+* @since 02/13/2015
+*/
+
+/**
+* Recurses a directory and deletes files inside
+*
+* Copied from php.net
+*
+* @param string $dir The driectory name
+* $return null
+*/
+function delTree($dir) {
+ $files = array_diff(scandir($dir), array('.','..'));
+ foreach ($files as $file) {
+ (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
+ }
+ return rmdir($dir);
+}
+
+/**
+* Initializes the listdiraux method with a starting directory point
+*
+* copied from php.net
+*
+* @param string $dir Starting directory
+* @return array FQ list of files
+*/
+function listdir($dir='.') {
+ if (!is_dir($dir)) {
+ return false;
+ }
+ $files = array();
+ listdiraux($dir, $files);
+
+ return $files;
+}
+
+/**
+* Recurses a directory structure and creates a list of files
+*
+* @param string $dir Starting directory
+* @param string[] $files By reference, the current file list
+* @return null
+*/
+function listdiraux($dir, &$files) {
+ $handle = opendir($dir);
+ while (($file = readdir($handle)) !== false) {
+ if ($file == '.' || $file == '..') {
+ continue;
+ }
+
+ if (preg_match('/v6$/',$file))
+ /*
+ * This is only v5 documentation
+ */
+ continue;
+
+ $filepath = $dir == '.' ? $file : $dir . '/' . $file;
+ if (is_link($filepath))
+ continue;
+ if (is_file($filepath))
+ $files[] = $filepath;
+ else if (is_dir($filepath))
+ listdiraux($filepath, $files);
+ }
+ closedir($handle);
+}
+/*
+* Clean up the documentation directory from prior use
+*/
+if (is_dir('documentation'))
+ deltree('documentation');
+mkdir('documentation');
+
+$files = listdir('documentation-base');
+sort($files, SORT_LOCALE_STRING);
+
+/*
+* Loop through files in documentation-base directory, creating a mirror
+* structure in documentation, and applying the post-process rules defined
+* below
+*/
+foreach ($files as $f) {
+
+ $r = str_replace('documentation-base','documentation',$f);
+ $dList = explode ('/',$r);
+ $titleList = $dList;
+ /*
+ * Get rid of the initial directory
+ */
+ array_shift($titleList);
+
+ $depth = count($dList) -2;
+ $dSlash = '';
+ while(count($dList) > 1)
+ {
+ $dSlash .= array_shift($dList) . '/';
+ if (!is_dir($dSlash))
+ mkdir($dSlash);
+ }
+ if (!is_file($f))
+ continue;
+ if (substr($f,-4) <> 'html')
+ {
+ /*
+ * An image or something else, copy unmodified
+ */
+ copy ($f,$r);
+ continue;
+ }
+
+ $prepend = str_repeat('../',$depth);
+
+ $doc = new DOMDocument();
+ @$doc->loadHTMLFile($f);
+
+ /*
+ * Remove Page Tools Group
+ */
+ $xpath = new DOMXPath($doc);
+
+ /*
+ * Remove Top Menu Tools Group, and add a link to the ADOdb site
+ */
+ $nodes = $xpath->query("//div[@class='tools group']");
+ foreach($nodes as $node) {
+ $pn = $node->parentNode;
+ $pn->removeChild($node);
+ $newChild = $doc->createElement('div','');
+ $newDiv = $pn->appendChild($newChild);
+ $newDiv->setAttribute('style','text-align:right');
+ $newChild = $doc->createElement('a','ADOdb Web Site');
+ $newA = $newDiv->appendChild($newChild);
+ $newA->setAttribute('href','http://adodb.org');
+ }
+
+ /*
+ * Remove Trace
+ */
+ $nodes = $xpath->query("//div[@class='breadcrumbs']");
+ foreach($nodes as $node) {
+ $node->parentNode->removeChild($node);
+ }
+
+ /*
+ * Remove Side Menu Tools Group
+ */
+ $nodes = $xpath->query("//div[@id='dokuwiki__pagetools']");
+ foreach($nodes as $node) {
+ $node->parentNode->removeChild($node);
+ }
+
+ /*
+ * Fix main links
+ */
+ $nodes = $xpath->query("//a[@class='wikilink1']");
+ foreach($nodes as $node) {
+ $n = $node->getAttribute('title');
+ $p = $prepend . str_replace(':','/',$n) . '.html';
+ $node->setAttribute('href', $p);
+ }
+
+ /*
+ * Fix In Page links
+ */
+ $nodes = $xpath->query("//a[@class='wikilink2']");
+ foreach($nodes as $node) {
+ $n = $node->getAttribute('title');
+ $p = $prepend . str_replace(':','/',$n) . '.html';
+ $node->setAttribute('href', $p);
+ }
+
+ /*
+ * Make Graphic point to first page. This will break if the image size
+ * ever changes.
+ */
+ $corePage = $prepend . '/index.html';
+ $nodes = $xpath->query("//img[@width='176']");
+ foreach($nodes as $node) {
+ $node->parentNode->setAttribute('href', $corePage);
+ }
+
+ /*
+ * Change title of page
+ */
+ $nodes = $xpath->query("//title");
+ foreach($nodes as $node) {
+
+
+ $docTitle = implode(':',$titleList);
+ $docTitle = str_replace('.html','',$docTitle);
+ $pn = $node->parentNode;
+ $pn->removeChild($node);
+ $newChild = $doc->createElement('title',$docTitle);
+ $pn->appendChild($newChild);
+
+ }
+
+ $doc->saveHTMLFile($r);
+
+ echo $r, "\n";
+}
+/*
+* Now remove the original index and replace it with the hardcopy documentation one
+*/
+unlink ('documentation/index.html');
+rename('documentation/adodb_index.html','documentation/index.html');
+
+/*
+* We could add in an auto zip and upload here, but this is a good place to
+* stop and check the output
+*/
+
+?>
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()