Sunday, April 1, 2012

Git-scribe gen 2x

‹prev | My Chain | next›

When last I worked on git-scribe, I had to rather hastily abandon my efforts to rebase my branch onto the upstream master. I had hoped to get the upstream syntax highlighting working with the resizing, cover image, and various other tweaks of mine. But I was past due for getting started with Dart for Hipsters, so I had to set it aside.

And tonight, I leave it set aside.... at least for a bit.

There is an incredibly annoying bug in my fork that I have been working around for 3 months and today I finally fix it. Whenever I update one of the ebook formats, I get something like:
➜  dart-book git:(master) git-scribe gen pdf                                                   
Error: File exists - (../jade/bin/jade, output/includes/websockets/node_modules/.bin/jade)
To get this to work, I need to remove that entire node_modules directory. Just removing the problem file is not sufficient:
➜  dart-book git:(master) git-scribe gen pdf
Error: File exists - (../jade/bin/jade, output/includes/websockets/node_modules/.bin/jade)
➜  dart-book git:(master) rm output/includes/websockets/node_modules/.bin/jade
➜  dart-book git:(master) git-scribe gen pdf
Error: File exists - (../express/bin/express, output/includes/websockets/node_modules/.bin/express)
➜  dart-book git:(master) rm -rf output/includes/websockets/node_modules/.bin
➜  dart-book git:(master) git-scribe gen pdf
Error: File exists - (jade.js, output/includes/websockets/node_modules/jade/lib/index.js)
➜  dart-book git:(master) rm -rf output/includes/websockets/node_modules
➜  dart-book git:(master) git-scribe gen pdf
GENERATING PDF
GENERATING DOCBOOK
asciidoc: reading: /etc/asciidoc/asciidoc.conf
asciidoc: reading: /home/cstrom/.asciidoc/asciidoc.conf
asciidoc: reading: /etc/asciidoc/asciidoc.conf
...
Making portrait pages on USletter paper (7.5inx9in)
But I need to do that every time. Well no more, dammit.

Rooting through git-scribe, I am reasonably sure that preparing the output directory is the source of my woes. So I add verbose to the FileUtils.cp_r call:
    def prepare_output_dir(dir='output')
      Dir.mkdir(dir) rescue nil
      FileUtils.cp_r "#{@wd}/book/.", dir, :verbose => true
      # ...
    end
I still get the failure, but now I have a system command to try:
➜  dart-book git:(master) git-scribe gen pdf     
cp -r /home/cstrom/repos/dart-book/book/. output
Error: File exists - (../jade/bin/jade, output/./includes/websockets/node_modules/.bin/jade)
Executing that cp.... works just fine:
➜  dart-book git:(master) cp -r /home/cstrom/repos/dart-book/book/. output

Eventually, I realize that the problem files are symbolic links that ruby's cp_r is not handling correctly:
➜  dart-book git:(master) find book -type l 
book/includes/websockets/node_modules/.bin/jade
book/includes/websockets/node_modules/.bin/express
book/includes/websockets/node_modules/jade/lib/index.js
➜  dart-book git:(master) find book -type l -ls
 35754    0 lrwxrwxrwx   1 cstrom   cstrom         16 Mar 12 23:23 book/includes/websockets/node_modules/.bin/jade -> ../jade/bin/jade
 35929    0 lrwxrwxrwx   1 cstrom   cstrom         22 Mar 12 23:23 book/includes/websockets/node_modules/.bin/express -> ../express/bin/express
 35118    0 lrwxrwxrwx   1 cstrom   cstrom          7 Mar 12 23:23 book/includes/websockets/node_modules/jade/lib/index.js -> jade.js
If I manually remove them, then the git-scribe gen works:
➜  dart-book git:(master) find output -type l -exec rm {} \; -print
output/includes/websockets/node_modules/.bin/jade
output/includes/websockets/node_modules/.bin/express
output/includes/websockets/node_modules/jade/lib/index.js
➜  dart-book git:(master) git-scribe gen pdf                       
cp -r /home/cstrom/repos/dart-book/book/. output
GENERATING PDF
GENERATING DOCBOOK
...
Making portrait pages on USletter paper (7.5inx9in)
I include test servers in certain directories to test the code that gets included into the book. This particular problem was for the web sockets chapter in Dart for Hipsters. This seems a legit thing to do, so I definitely need to address the problem in git-scribe, not in how I maintain my book.

To resolve this I could remove the symbolic links in ruby as well. That is a hassle and I can just as easily tell cp_r to remove all files before copy:
    def prepare_output_dir(dir='output')
      Dir.mkdir(dir) rescue nil
      FileUtils.cp_r "#{@wd}/book/.", dir, :remove_destination => true

      Dir.mkdir("#{dir}/stylesheets") rescue nil
      FileUtils.cp_r File.join(SCRIBE_ROOT, 'stylesheets'), dir
    end
That does the trick. Yay!

Looking through the stdlib ruby library, I think that :remove_destination => true works on files, not on directories. Either way, it should not affect git-scribe or my workflow. Still, that eases my conscious a bit.

With that, I can generate my book as many times as I want. I am so freaking happy.


Day #342

1 comment: