From: Jean-Michel Sarlat Date: Mon, 16 Apr 2012 18:57:05 +0000 (+0200) Subject: Initialisation du projet wslsock X-Git-Url: https://melusine.eu.org/syracuse/G/git/?a=commitdiff_plain;h=8eeae70ec8865386ec3d8b67efdb34bd62bf5feb;p=wslsock.git Initialisation du projet wslsock --- 8eeae70ec8865386ec3d8b67efdb34bd62bf5feb diff --git a/doc/gut2012/index.xml b/doc/gut2012/index.xml new file mode 100644 index 0000000..c74c9d4 --- /dev/null +++ b/doc/gut2012/index.xml @@ -0,0 +1,3 @@ + + Présentation (Journée GUTenberg 2012) + diff --git a/doc/gut2012/presentation.pdf b/doc/gut2012/presentation.pdf new file mode 100644 index 0000000..adec9b7 Binary files /dev/null and b/doc/gut2012/presentation.pdf differ diff --git a/doc/gut2012/wslsock-exemples.pdf b/doc/gut2012/wslsock-exemples.pdf new file mode 100644 index 0000000..8880e8a Binary files /dev/null and b/doc/gut2012/wslsock-exemples.pdf differ diff --git a/doc/gut2012/wslsock-exemples.tex b/doc/gut2012/wslsock-exemples.tex new file mode 100644 index 0000000..4a5acfb --- /dev/null +++ b/doc/gut2012/wslsock-exemples.tex @@ -0,0 +1,64 @@ +\documentclass[a4paper]{article} +\usepackage[frenchb]{babel} +\usepackage{wslsock} +\usepackage[margin=2cm]{geometry} +\usepackage[svgnames]{xcolor} +\usepackage{graphicx} +\usepackage{wsmath} +\usepackage{mathpazo} +\usepackage{fontspec} +\setmainfont[Ligatures=TeX]{TeX Gyre Bonum} +\setsansfont[Ligatures=TeX,Scale=MatchLowercase]{TeX Gyre Heros} + +\usepackage{fancyvrb} +\usepackage{pygmentize} +\usepackage{framed} +\newenvironment{gbar}[1][Wheat]{% + \def\FrameCommand{{\color{#1}\vrule width 3pt}\colorbox{Gainsboro}}% + \MakeFramed {\advance\hsize-\width \FrameRestore}}% +{\endMakeFramed} + +\def\Exercice#1{{\color{FireBrick}#1}} + +\begin{document} + +{\noindent\LARGE\bfseries Exemples d'utilisation de wslsock}\\ +{\color{Gainsboro}\rule{\linewidth}{0.8mm}}\vspace{-1.2em} + +\begin{flushright}\small\itshape\color{DodgerBlue} +Jean-Michel Sarlat --- \today +\end{flushright} + +\section*{Inclusion de figures} + +La macro \verb+\wslsincludegraphics+ s'utilise comme +\verb+\includegraphics+, à la différence que le fichier, s'il est +introuvable en local, est téléchargé via l'\emph{url} dont la base +est spécifiée via \verb+\wslsbase+. + +\begin{gbar}\input{inc/inc1-pyg.tex}\end{gbar} +\input{inc/inc1.tex} + +\newpage + +\section*{Inclusion de segments} + +La macro \verb+\wslsinput+ se substitue à +\verb+\input+ suivant la règle énoncée précedemment. + +\begin{gbar}\input{inc/inc2-pyg.tex}\end{gbar} +{\setlength{\baselineskip}{1.4em} +\input{inc/inc2.tex} +} +\newpage + +\section*{Inclusion de pages d'un fichier PDF} + +Avec \verb+\wslsockdownload+ on télécharge un fichier que l'on peut +exploiter ensuite selon les méthodes usuelles. + +\begin{gbar}\input{inc/inc3-pyg.tex}\end{gbar} +\input{inc/inc3.tex} + + +\end{document} \ No newline at end of file diff --git a/doc/index.xml b/doc/index.xml new file mode 100644 index 0000000..fb534ff --- /dev/null +++ b/doc/index.xml @@ -0,0 +1,3 @@ + + Documentation + diff --git a/index.xml b/index.xml new file mode 100644 index 0000000..eea4603 --- /dev/null +++ b/index.xml @@ -0,0 +1,3 @@ + + Paquet wslsock + diff --git a/web.xml b/web.xml new file mode 100644 index 0000000..f74109c --- /dev/null +++ b/web.xml @@ -0,0 +1,4 @@ + + wslsock + Jean-Michel Sarlat + \ No newline at end of file diff --git a/wslsock.lua b/wslsock.lua new file mode 100644 index 0000000..8ea3b17 --- /dev/null +++ b/wslsock.lua @@ -0,0 +1,55 @@ +-- Détermination de la taille d'un fichier +function wsls_fsize (name) + fso = io.open(name, "r") + s = fso:seek("end") + io.close(fso) + return s +end + +-- Détermination de l'extension d'un fichier +function wsls_fext (name) + return string.match(name, "(%.%a+)$") +end + +-- Détermination du fichier +function wsls_fname (tail) + return string.match(tail, "/?([%a%d%.%-]+)$") +end + +-- GET simple +function wsls_get (base, tail) + http = require("socket.http") + ltn12 = require("ltn12") + file = wsls_fname(tail) + out = io.open(file, "w") + r, c, h = http.request { + url = "http://" .. base .. tail, + sink = ltn12.sink.file(out) + } + if c == 200 then + print ("Le fichier " .. file .. "(" .. + wsls_fsize(file) .. " octets) est transféré !") + end +end + + +-- PUT simple +function wsls_put (base, tail) + http = require("socket.http") + ltn12 = require("ltn12") + file = wsls_fname(tail) + r, c, h = http.request { + method = "PUT", + url = "http://" .. base .. tail, + source = ltn12.source.file(io.open(file)), + headers = { + ["content-length"] = wsls_fsize(file) + } + } + if c == 200 then + print ("Le fichier " .. file .. "(" .. + wsls_fsize(file) .. " octets) est transféré !") + end +end + + diff --git a/wslsock.sty b/wslsock.sty new file mode 100644 index 0000000..d0fc4b4 --- /dev/null +++ b/wslsock.sty @@ -0,0 +1,24 @@ + +\directlua{dofile("wslsock.lua")} + +\newcommand\wslsbase[1]{ + \gdef\WSLSbase{#1} +} + +\newcommand\wslsinput[1]{ + \edef\fichier{\directlua{tex.print(wsls_fname("#1"))}}% + \IfFileExists{\fichier}{}{\directlua{wsls_get("\WSLSbase","#1")}}% + \input{\fichier} +} + +\newcommand\wslsdownload[1]{ + \edef\fichier{\directlua{tex.print(wsls_fname("#1"))}}% + \IfFileExists{\fichier}{}{\directlua{wsls_get("\WSLSbase","#1")}}% +} + +\newcommand\wslsincludegraphics[2][]{ + \edef\fichier{\directlua{tex.print(wsls_fname("#2"))}}% + \IfFileExists{\fichier}{}{\directlua{wsls_get("\WSLSbase","#2")}}% + \includegraphics[#1]{\fichier} +} +