[rfdoc] push by janne.piironen@gmail.com - upload.py: made uploader not fail on the first remote error.... on 2014-03-27 11:18 GMT

6 views
Skip to first unread message

codesite...@google.com

unread,
Mar 27, 2014, 7:18:37 AM3/27/14
to rfdoc-...@googlegroups.com
Revision: 2e1d85488cb5
Branch: default
Author: Janne Piironen <janne.p...@gmail.com>
Date: Thu Mar 27 11:18:13 2014 UTC
Log: upload.py: made uploader not fail on the first remote error.

Update issue 30
Status: Done

upload.py now collects all the failed file uploads in a list and prints it
out at the end of execution. Uploading will not stop to the first error,
instead all found/given files are tried to be uploaded even when some of
the uploads fail.
http://code.google.com/p/rfdoc/source/detail?r=2e1d85488cb5

Modified:
/atest/uploader.txt
/src/rfdoc/upload.py

=======================================
--- /atest/uploader.txt Wed Mar 26 21:07:59 2014 UTC
+++ /atest/uploader.txt Thu Mar 27 11:18:13 2014 UTC
@@ -6,6 +6,7 @@
${SCRIPT NAME} upload.py
${SCRIPT PATH} ${CURDIR}${/}..${/}src${/}rfdoc${/}${SCRIPT
NAME}
${EXAMPLE LIBRARY SOURCE} ${TESTDATA PATH}${/}sources${/}example_lib.py
+${EMPTY KEYWORDS XML} ${TESTDATA
PATH}${/}xmls${/}invalid${/}empty_keywords.xml
${EXAMPLE LIBRARY XML V1} ${TESTDATA
PATH}${/}xmls${/}ExampleLibrary_version_1.xml
${EXAMPLE LIBRARY XML V2} ${TESTDATA
PATH}${/}xmls${/}ExampleLibrary_version_2.xml
@{EXAMPLE LIB KEYWORDS} My Keyword self Does nothing. Your Keyword
self, arg Takes one argument and does nothing with it.
@@ -105,19 +106,30 @@
With library not found
${rc} ${output}= Run With -u ${BASE URL} NotExistingLibrary
Should Print NotExistingLibrary Not Found
- Should Exit With 0
+ Should Exit With 1

With an error in parsing one library
+ [Setup] Given no libraries exist in RFDoc
${rc} ${output}= Run With -u ${BASE URL} InvalidLibrary ${EXAMPLE
LIBRARY XML V1}
Should Print InvalidLibrary Failed To Update
Should Print ${EXAMPLE LIBRARY XML V1} Updated
- Should Exit With 0
+ RFDoc contains versioned library ExampleLibrary version 1
+ Should Exit With 1

With invalid host given
${rc} ${output}= Run With --url=${INVALID URL} ${EXAMPLE LIBRARY XML
V1}
Should Print ${INVALID URL} Is Invalid Host
Should Exit With 1

+With a remote error
+ [Setup] Given no libraries exist in RFDoc
+ ${rc} ${output}= Run With -u ${BASE URL} ${EMPTY KEYWORDS XML}
${EXAMPLE LIBRARY XML V1}
+ Should Print empty_keywords.xml Contains No Keywords
+ Should Print ${EMPTY KEYWORDS XML} In Errorlist
+ Should Print ${EXAMPLE LIBRARY XML V1} Updated
+ RFDoc contains versioned library ExampleLibrary version 1
+ Should Exit With 1
+
*** Keywords ***
Run With ${arguments}
${rc} ${output}= Run And Return Rc And Output ${SCRIPT_PATH}
${arguments}
@@ -149,3 +161,10 @@

Should Print ${host} Is Invalid Host
Should Contain ${output} ${SCRIPT_NAME}: Remote error: connection
refused to '${host}', check that the host responds and is reachable.
+
+Should Print ${test_library} Contains No Keywords
+ Should Contain ${output} ${SCRIPT_NAME}: Remote error: Given test
library file ${test_library} contains no keywords.
+
+Should Print ${test_library} In Errorlist
+ Should Contain ${output} ERROR: Uploading 1 file(s) failed:
+ Should Contain ${output} * ${test_library}
=======================================
--- /src/rfdoc/upload.py Wed Mar 26 21:07:59 2014 UTC
+++ /src/rfdoc/upload.py Thu Mar 27 11:18:13 2014 UTC
@@ -39,8 +39,9 @@
self._uploader = XmlUploader(self._options.target_url)

def run(self):
- try:
- for library in self._options.libraries:
+ failed = []
+ for library in self._options.libraries:
+ try:
xml_doc = StringIO()
# LibraryDocumentation().save() calls close() for the
underlying
# file but closing StringIO object discards its data.
@@ -56,6 +57,7 @@

LibraryDocumentation(library).save(xml_doc, 'xml')
except DataError, e:
message = "Library not found" if 'ImportError' in
e.message else e.message
+ failed.append(library)
sys.stderr.write("Skipping '%s' due to an
error: %s.\n" %
(library, message))
continue
@@ -64,12 +66,16 @@
sys.stdout.write("Updated documentation for '%s'.\n" %
library)
finally:
xml_doc.original_close()
- except DataError, e:
- sys.stderr.write('%s: Remote error: %s\n' %
(os.path.basename(__file__),
- e.message))
+ except DataError, e:
+ failed.append(library)
+ sys.stderr.write('%s: Remote error: %s\n' %
(os.path.basename(__file__),
+ e.message))
+ if failed:
+ sys.stderr.write('\nERROR: Uploading %d file(s) failed:\n' %
len(failed))
+ for name in failed:
+ sys.stderr.write('* %s\n' % name)
exit(1)

-
class ImprovedOptionParser(OptionParser):

# This prevents newlines from getting discarded from the help text.
Reply all
Reply to author
Forward
0 new messages