~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to src/pkg/Interface/Command/Register.hs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{-# LANGUAGE OverloadedStrings #-}
2
 
 
3
 
module Interface.Command.Register where
4
 
 
5
 
import Control.Applicative
6
 
import qualified Data.ByteString.Char8
7
 
  as BS
8
 
import qualified Distribution.ParseUtils
9
 
  as Cabal
10
 
import qualified Distribution.InstalledPackageInfo
11
 
  as Cabal
12
 
import System.Environment
13
 
 
14
 
import qualified Agda.Packaging.Config
15
 
  as Agda
16
 
import qualified Agda.Packaging.Database
17
 
 as Agda
18
 
import qualified Agda.Packaging.Monad
19
 
  as Agda
20
 
import qualified Agda.Packaging.Types
21
 
  as Agda
22
 
 
23
 
import Interface.Exit
24
 
import Interface.Options
25
 
--import Utils
26
 
 
27
 
--------------------------------------------------------------------------------
28
 
 
29
 
envRegex :: BS.ByteString
30
 
envRegex = BS.pack "\\${[a-zA-Z0-9_]+}"
31
 
 
32
 
envSubst :: BS.ByteString -> IO BS.ByteString
33
 
envSubst s
34
 
  |  ("${" `BS.isPrefixOf`) s
35
 
  && ("}"  `BS.isSuffixOf`) s = BS.pack <$> result
36
 
  | otherwise                 = return s
37
 
    where
38
 
      result = getEnv
39
 
             $ BS.unpack
40
 
             $ BS.takeWhile (/= '}')
41
 
             $ BS.drop 2 s
42
 
 
43
 
registerPkg :: FilePath -> Agda.AgdaPkg Opt ()
44
 
registerPkg fileName = undefined
45
 
  -- FIXME: rewrite
46
 
  {-
47
 
  do
48
 
  npkgDBs <- Agda.asks Agda.configPkgDBStack
49
 
  case npkgDBs of
50
 
    []           -> undefined
51
 
    dbToModify:_ -> do
52
 
      contents         <- Agda.liftIO $
53
 
        if fileName == "-" then
54
 
          BS.getContents
55
 
        else
56
 
          BS.readFile fileName
57
 
      expandedContents <- return contents
58
 
      pkgInfo          <- parsePkgInfo expandedContents
59
 
      let cond pkgInfo' = Cabal.installedPackageId pkgInfo'
60
 
                       /= Cabal.installedPackageId pkgInfo
61
 
          newDB         = pkgInfo : filter cond $ Agda.db dbToModify
62
 
      Agda.writePkgDBToFile newDB $ Agda.dbName dbToModify
63
 
  where
64
 
    parsePkgInfo :: BS.ByteString
65
 
                 -> Agda.AgdaPkg Opt Cabal.InstalledPackageInfo
66
 
    parsePkgInfo contents =
67
 
      case Cabal.parseInstalledPackageInfo $ BS.unpack contents of
68
 
        Cabal.ParseFailed err    ->
69
 
          case Cabal.locatedErrorMsg err of
70
 
            (Nothing, s) -> Agda.liftIO $ die                     s
71
 
            (Just l , s) -> Agda.liftIO $ die $ show l ++ ": " ++ s
72
 
        Cabal.ParseOk _warns res -> do
73
 
          return res
74
 
    -}