[latex3-commits] [git/LaTeX3-latex3-l3build] master: Pass curl data as file (3c7ba01)

GitHub noreply at github.com
Sun Feb 10 10:38:49 CET 2019


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/3c7ba01216e1a0a990a141308c06e2042a87cf82

>---------------------------------------------------------------

commit 3c7ba01216e1a0a990a141308c06e2042a87cf82
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Feb 10 09:38:49 2019 +0000

    Pass curl data as file


>---------------------------------------------------------------

3c7ba01216e1a0a990a141308c06e2042a87cf82
 l3build-upload.lua |   61 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 15 deletions(-)

diff --git a/l3build-upload.lua b/l3build-upload.lua
index 4afee06..4256ed0 100644
--- a/l3build-upload.lua
+++ b/l3build-upload.lua
@@ -29,6 +29,7 @@ local tostring = tostring
 local close = io.close
 local flush = io.flush
 local open  = io.open
+local output = io.output
 local popen = io.popen
 local read  = io.read
 local write = io.write
@@ -93,9 +94,12 @@ function upload(tagnames)
     uploadconfig.announcement = assert(f:read('*a'))
     close(f)
   end
-  uploadconfig.announcement = options["message"] or uploadconfig.announcement
+  uploadconfig.announcement = options["message"] or uploadconfig.announcement or file_contents(uploadconfig.announcement_file)
   uploadconfig.email = options["email"] or uploadconfig.email
 
+
+  uploadconfig.note =   uploadconfig.note  or file_contents(uploadconfig.note_file)
+
   local tagnames = tagnames or { }
   uploadconfig.version = tagnames[1] or uploadconfig.version
 
@@ -115,14 +119,27 @@ function upload(tagnames)
 
   ctan_post = construct_ctan_post(uploadfile,options["debug"])
 
-  if options["debug"] then
+
+-- curl file version
+  local curlopt=open(ctanzip .. ".curlopt","w")
+  output(curlopt)
+  write(ctan_post)
+  close(curlopt)
+  
+  ctan_post=curlexe .. " --config " .. ctanzip .. ".curlopt"
+  
+
+if options["debug"] then
+    ctan_post = ctan_post ..  ' https://httpbin.org/post'
     fp_return = shell(ctan_post)
     print('\n\nCURL COMMAND:')
     print(ctan_post)
     print("\n\nHTTP RESPONSE:")
     print(fp_return)
     return 1
-  end
+else
+    ctan_post = ctan_post ..  ' https://ctan.org/submit/'
+end
 
   -- call post command to validate the upload at CTAN's validate URL
   local exit_status=0
@@ -150,12 +167,12 @@ function upload(tagnames)
   end
 
   -- if upload requested and validation succeeded repost to the upload URL
-  if (exit_status==0 or exit_status==nil) then
+    if (exit_status==0 or exit_status==nil) then
     if (ctanupload ~=nil and ctanupload ~=false and ctanupload ~= true) then
       print("Validation successful, do you want to upload to CTAN? [y/n]" )
       local answer=""
-      write("> ")
-      flush()
+      io.stdout:write("> ")
+      io.stdout:flush()
       answer=read()
       if(lower(answer,1,1)=="y") then
         ctanupload=true
@@ -195,7 +212,8 @@ end
 function construct_ctan_post(uploadfile,debug)
 
   -- start building the curl command:
-  ctan_post = curlexe .. " "
+-- commandline  ctan_post = curlexe .. " "
+  ctan_post=""
   
   -- build up the curl command field-by-field:
 
@@ -225,12 +243,8 @@ function construct_ctan_post(uploadfile,debug)
   if os_type == "windows" then
     qq = '\"'
   end
-  ctan_post = ctan_post .. ' --form ' .. qq .. 'file=@' .. tostring(uploadfile) .. ';filename=' .. tostring(uploadfile) .. qq
-  if debug then
-    ctan_post = ctan_post ..  ' https://httpbin.org/post'
-  else
-    ctan_post = ctan_post ..  ' https://ctan.org/submit/'
-  end
+-- commandline   ctan_post = ctan_post .. ' --form ' .. qq .. 'file=@' .. tostring(uploadfile) .. ';filename=' .. tostring(uploadfile) .. qq
+  ctan_post = ctan_post .. '\nform="file=@' .. tostring(uploadfile) . ';filename=' .. tostring(uploadfile) .. '"'
 
   return ctan_post
 
@@ -270,7 +284,8 @@ function ctan_single_field(fname,fvalue,max,desc,mandatory)
       vs = vs:gsub('"','\\"')
       vs = vs:gsub('`','\\`')
       vs = vs:gsub('\n','\\n')
-      ctan_post=ctan_post .. ' --form "' .. fname .. "=" .. vs .. '"'
+-- for strings on commandline version      ctan_post=ctan_post .. ' --form "' .. fname .. "=" .. vs .. '"'
+      ctan_post=ctan_post .. '\nform="' .. fname .. '=' .. vs .. '"'
     end
   else
     error("The value of the field '" .. fname .."' must be a scalar not a table")
@@ -301,7 +316,7 @@ function input_multi_line_field (name)
         field = field .. "\n" .. answer_line
       end
      end
-  until (return_count==3 or answer_line==nil)
+  until (return_count==3 or answer_line==nil or answer_line=='\004')
   return field
 end
 
@@ -316,3 +331,19 @@ function input_single_line_field(name)
   return field
 end
 
+
+-- if filename is non nil and file readable return contents otherwise nil
+function file_contents (filename)
+  if filename ~= nil then
+    local f= open(filename,"r")
+    if f==nil then
+      return nil
+    else 
+      local s = f:read("*all")
+      close(f)
+      return s
+    end
+  else
+    return nil
+  end
+end





More information about the latex3-commits mailing list