Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDirectory file #173

Closed
ghost opened this issue Oct 1, 2014 · 15 comments
Closed

getDirectory file #173

ghost opened this issue Oct 1, 2014 · 15 comments

Comments

@ghost
Copy link

ghost commented Oct 1, 2014

Hi,

Is there any way of getting the directory of one file. For example getDirectory foo/baa/roo/f.txt would return foo/baa/roo/

@ndmitchell
Copy link
Owner

See dropFileName which you can import with import Development.Shake.FilePath. Does that do what you were after?

@ghost
Copy link
Author

ghost commented Oct 2, 2014

I suppose. Can you put examples in this documentation? Is that possible?

@ndmitchell
Copy link
Owner

I did actually write the filepath library, but that was many years ago, and to change it I now need to go through some fairly complex approval process. On the plus side, I was going to do that anyway with some other changes I had in mind for filepath (migrating pieces I did for Shake), so I've raised #174 and will track that there.

@ghost
Copy link
Author

ghost commented Oct 14, 2014

How can I run command in an specific directory?

I have this:

import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
import System.FilePath.Posix
import Development.Shake.FilePath

main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_shake_build/"} $ do
    want ["classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf"]

    -- # ESPA 2
    -- ## Generar el document final (pdf) amb mode=solucions-fora
    "classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf" *> \out -> do
        let c = out -<.> "conTeXt"
        need [c]
        () <- cmd Shell "cd " [dropFileName c]
        () <- cmd Shell ". /usr/local/bin/context/tex/setuptex"
        cmd Shell "context " [c] "--mode=solucions-fora --result " [out];

but context is running in shake directory rather than in [dropFileName c] directory.

What's wrong?

@ghost ghost reopened this Oct 14, 2014
@ndmitchell
Copy link
Owner

Each shell spawns, runs and closes, so cd doesn't have any effect. You should instead use the Cwd operation, such as:

    () <- cmd (Cwd $ takeDirectory c) Shell ". /usr/local/bin/context/tex/setuptex"
    cmd (Cwd $ takeDirectory c) Shell "context " [c] "--mode=solucions-fora --result " [out];

In general, never change the current directory (which is a global resource and responds poorly to multithreading), instead use Cwd which spawns the new process with a new working directory.

I also switched dropFileName to takeDirectory, which removes the trailing slash (probably no effect, but takeDirectory is a bit more correct).

@ghost
Copy link
Author

ghost commented Oct 14, 2014

It hangs me:

main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_shake_build/"} $ do
    want ["classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf"]

    -- # ESPA 2
    -- ## Generar el document final (pdf) amb mode=solucions-fora
    "classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf" *> \out -> do
        let c = out -<.> "conTeXt"
        need [c]
        () <- cmd Shell ". /usr/local/bin/context/tex/setuptex"
        cmd (Cwd $ takeDirectory c) Shell "context " [c] "--mode=solucions-fora --result " [out];


results:

$ ./shaking 
# . (for classe/ESPA2/planificaci�/Tema1-Nombres-enters/80-Nombres-enters.pdf)
# context (for classe/ESPA2/planificaci�/Tema1-Nombres-enters/80-Nombres-enters.pdf)

mtx-context     | run 1: luatex --fmt="/home/xan/.texlive/texmf-var/luatex-cache/context/0399a8df3aef8d154781d0a9c2b8e28d/formats/luatex/cont-en" --jobname="80-Nombres-enters" --lua="/home/xan/.texlive/texmf-var/luatex-cache/context/0399a8df3aef8d154781d0a9c2b8e28d/formats/luatex/cont-en.lui" --no-parse-first-line --c:currentrun=1 --c:fulljobname="classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.conTeXt" --c:input="classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.conTeXt" --c:kindofrun=1 --c:maxnofruns=8 --c:mode="solucions-fora" --c:result "cont-yes.mkiv"
This is LuaTeX, Version beta-0.79.1 (TeX Live 2014/Arch Linux) (rev 4971) 
 \write18 enabled.
open source     > 1 > 1 > /usr/share/texmf-dist/tex/context/base/cont-yes.mkiv

ConTeXt  ver: 2014.05.21 22:04 MKIV beta  fmt: 2014.9.25  int: english/english

system          > 'cont-new.mkiv' loaded
open source     > 2 > 2 > /usr/share/texmf-dist/tex/context/base/cont-new.mkiv
close source    > 2 > 2 > /usr/share/texmf-dist/tex/context/base/cont-new.mkiv
system          > files > jobname '80-Nombres-enters', input 'classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.conTeXt', result 'true'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active

@ghost
Copy link
Author

ghost commented Oct 14, 2014

By other hand, UTF-8 does not display correctly (see instead of ó in the filename)

@ghost
Copy link
Author

ghost commented Oct 14, 2014

Now:

main :: IO ()
main = shakeArgs shakeOptions{shakeFiles="_shake_build/"} $ do
    want ["classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf"]

    -- # ESPA 2
    -- ## Generar el document final (pdf) amb mode=solucions-fora
    "classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf" *> \out -> do
        let c = out -<.> "conTeXt"
        need [c]
        () <- cmd Shell ". /usr/local/bin/context/tex/setuptex"
        cmd (Cwd $ takeDirectory c) Shell "context " [takeFileName c] "--mode=solucions-fora --result " [out];

it's better but it hangs at the end

@ghost
Copy link
Author

ghost commented Oct 14, 2014

ConTeXt runs twice by default: the first time it runs with jobname '80-Nombres-enters', input './80-Nombres-enters.conTeXt', result 'true' but in the second, with files > jobname '80-Nombres-enters', input 'classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf', result 'true'

@ghost
Copy link
Author

ghost commented Oct 14, 2014

This

    -- # ESPA 2
    -- ## Generar el document final (pdf) amb mode=solucions-fora
    "classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf" *> \out -> do
        let c = out -<.> "conTeXt"
        need [c]
        () <- cmd Shell ". /usr/local/bin/context/tex/setuptex"
        cmd (Cwd $ takeDirectory c) Shell "context " [takeFileName c] "--mode=solucions-fora --result " [takeFileName out];

solves that, but now I have another error.

@ndmitchell
Copy link
Owner

So what's the current error? Or are you on top of that?

@ghost
Copy link
Author

ghost commented Oct 14, 2014

UTF. I think shake handles wrongly.

My file is UTF and it seems context does not recognizes. Is shake modifying
the encoding of the file?

2014-10-14 16:23 GMT+02:00 Neil Mitchell notifications@github.com:

So what's the current error? Or are you on top of that?


Reply to this email directly or view it on GitHub
#173 (comment).

@ghost
Copy link
Author

ghost commented Oct 14, 2014

The exact error is:

tx-context     | run 2: luatex --fmt="/home/xan/.texlive/texmf-var/luatex-cache/context/0399a8df3aef8d154781d0a9c2b8e28d/formats/luatex/cont-en" --jobname="80-Nombres-enters" --lua="/home/xan/.texlive/texmf-var/luatex-cache/context/0399a8df3aef8d154781d0a9c2b8e28d/formats/luatex/cont-en.lui" --no-parse-first-line --c:currentrun=1 --c:fulljobname="./80-Nombres-enters.pdf" --c:input="./80-Nombres-enters.pdf" --c:kindofrun=1 --c:maxnofruns=8 --c:mode="solucions-fora" --c:result "cont-yes.mkiv"
This is LuaTeX, Version beta-0.79.1 (TeX Live 2014/Arch Linux) (rev 4971) 
 \write18 enabled.
open source     > 1 > 1 > /usr/share/texmf-dist/tex/context/base/cont-yes.mkiv

ConTeXt  ver: 2014.05.21 22:04 MKIV beta  fmt: 2014.9.25  int: english/english

system          > 'cont-new.mkiv' loaded
open source     > 2 > 2 > /usr/share/texmf-dist/tex/context/base/cont-new.mkiv
close source    > 2 > 2 > /usr/share/texmf-dist/tex/context/base/cont-new.mkiv
system          > files > jobname '80-Nombres-enters', input './80-Nombres-enters.pdf', result 'true'
fonts           > latin modern fonts are not preloaded
languages       > language 'en' is active
open source     > 2 > 3 > /home/xan/SYNC/cepasud-raw/classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf

tex error       > error on line 6 in file /home/xan/SYNC/cepasud-raw/classe/ESPA2/planificació/Tema1-Nombres-enters/80-Nombres-enters.pdf: ! String contains an invalid utf-8 sequence

l.6 x^
    �V�n^^T1^^P��W�^^G0��[B+e��   �[�^^S^^H^^N�^^C\�}����M...

 1     %PDF-1.6


@ndmitchell
Copy link
Owner

To Shake, all files are binary, and the errors you are seeing files are only being processed with context. Is it possible you have a UTF8 variable set wrong in your shell? Or that your Latex can't use UTF8? Or do you have other places where you are calling readFile'? It's certainly possible that won't be UTF8 safe by default.

@ghost
Copy link
Author

ghost commented Oct 24, 2014

I comment the exact issue #183

@ghost ghost closed this as completed Oct 24, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant