This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 4c69096  Use library routines
4c69096 is described below

commit 4c69096769e2640200bc92d5a0e7e371f1553e6d
Author: Sebb <[email protected]>
AuthorDate: Thu Jun 11 15:59:47 2020 +0100

    Use library routines
---
 www/board/agenda/models/agenda.rb | 23 +++++++++++++++--------
 www/members/mentor-update.cgi     | 12 +++++-------
 www/members/proxy.cgi             | 23 +++++++----------------
 www/officers/surveys.cgi          |  7 ++-----
 www/treasurer/bill-upload.cgi     | 12 ++++--------
 5 files changed, 33 insertions(+), 44 deletions(-)

diff --git a/www/board/agenda/models/agenda.rb 
b/www/board/agenda/models/agenda.rb
index cdb3d4b..a6d3039 100755
--- a/www/board/agenda/models/agenda.rb
+++ b/www/board/agenda/models/agenda.rb
@@ -139,11 +139,18 @@ class Agenda
     #extract context from block
     _, env = eval('[_, env]', block.binding)
 
-    if env.password
-      auth ||= [['--username', env.user, '--password', env.password]]
+    if auth # was it passed in?
+      creds = {}
+      auth.flatten.each_slice(2) do |k,v|
+        creds[:user] = v if k == '--username'
+        creds[:password] = v if k == '--password'
+      end
     else
-      auth ||= [[]]
-    end
+      if env.password
+        creds = {env: env}
+      else
+        creds = {}
+      end
 
     file.untaint if file =~ /\Aboard_\w+_[\d_]+\.txt\z/
 
@@ -158,11 +165,11 @@ class Agenda
 
       # check out empty directory
       board = ASF::SVN.getInfoItem(FOUNDATION_BOARD,'url')
-      _.system ['svn', 'checkout', auth, '--depth', 'empty', board, dir]
+      ASF::SVN.svn_('checkout', board, _, {args: ['--depth', 
'empty']}.merge(creds))
 
       # update the file in question
       path = File.join(dir, file)
-      _.system ['svn', 'update', auth, path]
+      ASF::SVN.svn_('update', path, _, {env: env})
 
       # invoke block, passing it the current contents of the file
       if block and message
@@ -172,7 +179,7 @@ class Agenda
         # if the output differs, update and commit the file in question
         if output != input
           IO.write(path, output)
-          commit_rc = _.system ['svn', 'commit', auth, path, '-m', message]
+          commit_rc = ASF::SVN.svn_('commit', path, _, {argv: ['--message', 
message]}.merge(creds))
         end
       else
         output = IO.read(path)
@@ -195,7 +202,7 @@ class Agenda
         if retries > 0
           work_file.close
           sleep rand(41-retries*2)*0.1 if retries <= 20
-          update(file, message, retries-1, &block)
+          update(file, message, retries-1, &block) # recursive call
         else
           raise Exception.new("svn commit failed")
         end
diff --git a/www/members/mentor-update.cgi b/www/members/mentor-update.cgi
index 25437fe..8ee86cf 100755
--- a/www/members/mentor-update.cgi
+++ b/www/members/mentor-update.cgi
@@ -125,22 +125,20 @@ def send_form(formdata: {})
   end
   
   Dir.mktmpdir do |tmpdir|
-    credentials = ['--username', $USER, '--password', $PASSWORD]
-    svnopts = ['--no-auth-cache', '--non-interactive']
+    credentials = {user: $USER, password: $PASSWORD}
     # TODO: investigate if we should to --depth empty and attempt to get only 
that mentor's file
-    _.system ['svn', 'checkout', MentorFormat::MENTORS_SVN, tmpdir.untaint, 
svnopts, credentials]
-
+    ASF::SVN.svn_('checkout', [MentorFormat::MENTORS_SVN, tmpdir.untaint], _, 
credentials)
     Dir.chdir tmpdir do
       if File.exist? fn
         File.write(fn, mentor_update + "\n")
-        _.system ['svn', 'st']
+        ASF::SVN.svn_('status','.', _)
         message = "Updating my mentoring data (whimsy)"
       else
         File.write(fn, mentor_update + "\n")
-        _.system ['svn', 'add', fn]
+        ASF::SVN.svn_('add', fn, _)
         message = "#{$USER} += mentoring volunteer (whimsy)"
       end
-      rc = _.system ['svn', 'commit', fn, '--message', message, svnopts, 
credentials]
+      rc = ASF::SVN.svn_('commit', fn, _, {args: ['--message', 
message]}.merge(credentials)]
     end
   end
   
diff --git a/www/members/proxy.cgi b/www/members/proxy.cgi
index c397255..3037acd 100755
--- a/www/members/proxy.cgi
+++ b/www/members/proxy.cgi
@@ -181,19 +181,14 @@ def emit_post(cur_mtg_dir, meeting)
     Dir.mktmpdir do |tmpdir|
       svn =  ASF::SVN.getInfoItem(File.join(MEETINGS,meeting),'url')
 
-      _.system [
-        'svn', 'checkout', '--quiet', svn.untaint, tmpdir.untaint,
-        ['--no-auth-cache', '--non-interactive'],
-        (['--username', $USER, '--password', $PASSWORD] if $PASSWORD)
-      ]
-
+      ASF::SVN.svn_('checkout',[svn.untaint, tmpdir.untaint], _, 
+                    {args: '--quiet', user: $USER, password: $PASSWORD})
       Dir.chdir(tmpdir) do
         # write proxy form
         filename = "proxies-received/#$USER.txt".untaint
         File.write(filename, proxyform)
-        _.system ['svn', 'add', filename]
-        _.system ['svn', 'propset', 'svn:mime-type',
-          'text/plain; charset=utf-8', filename]
+        ASF::SVN.svn_('add', filename, _)
+        ASF::SVN.svn_('propset', ['svn:mime-type', 'text/plain; 
charset=utf-8', filename], _)
 
         # get a list of proxies
         list = Dir['proxies-received/*.txt'].map do |file|
@@ -233,13 +228,9 @@ def emit_post(cur_mtg_dir, meeting)
         IO.write('proxies', proxies)
 
         # commit
-        _.system [
-          'svn', 'commit', filename, 'proxies',
-          '-m', "assign #{@proxy} as my proxy",
-          ['--no-auth-cache', '--non-interactive'],
-          (['--username', $USER, '--password', $PASSWORD] if $PASSWORD)
-        ]
-        # TODO: send email to @proxy per WHIMSY-78
+        ASF::SVN.svn_('commit',[filename, 'proxies'], _, 
+          {args: ['--message', "assign #{@proxy} as my proxy"], user: $USER, 
password: $PASSWORD})
+# TODO: send email to @proxy per WHIMSY-78
       end
     end
   end
diff --git a/www/officers/surveys.cgi b/www/officers/surveys.cgi
index ec47285..4b338b1 100755
--- a/www/officers/surveys.cgi
+++ b/www/officers/surveys.cgi
@@ -118,9 +118,7 @@ def submit_survey(formdata: {})
   rc = 999 # Ensure it's a bogus value
   Dir.mktmpdir do |tmpdir|
     tmpdir.untaint
-    credentials = ['--username', $USER, '--password', $PASSWORD]
-    svnopts = ['--depth',  'files', '--no-auth-cache', '--non-interactive']
-    _.system ['svn', 'checkout', get_survey_root(), tmpdir, svnopts, 
credentials]
+    ASF::SVN.svn_('checkout',[get_survey_root(), tmpdir],_,{args: ['--depth', 
'files'], user: $USER, password: $PASSWORD})
     
     survey_data = JSON.parse(File.read(filename), :symbolize_names => true)
     # Add user data (may overwrite existing entry!)
@@ -130,8 +128,7 @@ def submit_survey(formdata: {})
 
     File.write(filename, JSON.pretty_generate(survey_data))
     Dir.chdir tmpdir do
-      # rc = _.system ['svn', 'commit', filename, '--message', "Survey 
submission (whimsy)",
-      #   ['--no-auth-cache', '--non-interactive'], credentials]
+      # rc = ASF::SVN.svn_('commit', filename, _, {args: ['--message', "Survey 
submission (whimsy)"], user: $USER, password: $PASSWORD})
     end
   end
   if rc == 0
diff --git a/www/treasurer/bill-upload.cgi b/www/treasurer/bill-upload.cgi
index cb88c4c..459d396 100755
--- a/www/treasurer/bill-upload.cgi
+++ b/www/treasurer/bill-upload.cgi
@@ -105,18 +105,14 @@ _html do
             Dir.mktmpdir do |tmpdir|
               tmpdir.untaint
 
-              _.system ['svn', 'checkout', File.join(bills, @dest), tmpdir,
-                '--depth=empty',
-                ['--no-auth-cache', '--non-interactive'],
-                (['--username', $USER, '--password', $PASSWORD] if $PASSWORD)]
+              ASF::SVN.svn_('checkout', [File.join(bills, @dest), tmpdir], _, 
+                  {args: '--depth=empty', user: $USER, password: $PASSWORD})
 
               Dir.chdir tmpdir do
                 IO.binwrite(name, @file.read)
-                _.system ['svn', 'add', name]
+                ASF::SVN.svn_('add', name, _)
 
-                _.system ['svn', 'commit', name, '--message', @message,
-                  ['--no-auth-cache', '--non-interactive'],
-                  (['--username', $USER, '--password', $PASSWORD] if 
$PASSWORD)]
+                ASF::SVN.svn_('commit', name, _, {user: $USER, password: 
$PASSWORD})
               end
             end
           end

Reply via email to