Created
January 9, 2012 04:13
-
-
Save wavewave/1581044 to your computer and use it in GitHub Desktop.
script for change absolute link to relative link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main where | |
| import Control.Concurrent | |
| import Control.Monad | |
| import Data.UUID | |
| import System.Directory | |
| import System.FilePath | |
| import System.Process | |
| import System.Posix.Files | |
| main :: IO () | |
| main = do | |
| putStrLn "changing absolute link to relative link" | |
| cdir <- getCurrentDirectory | |
| lst <- getDirectoryContents cdir | |
| mapM_ scriptaction . map fromString $ lst | |
| scriptaction :: Maybe UUID -> IO () | |
| scriptaction = | |
| maybe (return ()) $ \uuid -> do | |
| let str = toString uuid | |
| odir <- getCurrentDirectory | |
| let ndir = odir </> str </> "v0" </> "page" | |
| doesDirectoryExist ndir >>= \b -> when b $ do | |
| setCurrentDirectory ndir | |
| lst <- return . filter isSVG =<< getDirectoryContents ndir | |
| putStrLn (str ++ ": " ) | |
| mapM_ lnaction lst | |
| setCurrentDirectory odir | |
| isSVG :: FilePath -> Bool | |
| isSVG fp = takeExtension fp == ".svg" | |
| lnaction :: FilePath -> IO () | |
| lnaction fp = do | |
| lfp <- readSymbolicLink fp | |
| putStrLn $ fp ++ " -> " ++ lfp | |
| let fn = takeFileName lfp | |
| putStrLn $ "filename = " ++ fn | |
| removeLink fp | |
| threadDelay 100000 | |
| system $ "ln -s ../data/" ++ fn ++ " " ++ fp | |
| return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment