readpyc (empty) → 0.1.0
raw patch · 4 files changed
+141/−0 lines, 4 filesdep +basedep +bliplibdep +parseargssetup-changed
Dependencies added: base, bliplib, parseargs
Files
- LICENSE +30/−0
- Setup.lhs +3/−0
- readpyc.cabal +27/−0
- src/Main.hs +81/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Bernard Pope 2012, 2013++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Bernard Pope nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ readpyc.cabal view
@@ -0,0 +1,27 @@+Name: readpyc+Version: 0.1.0+Synopsis: Read and pretty print Python bytecode (.pyc) files.+Homepage: https://github.com/bjpop/blip +License: BSD3+License-file: LICENSE+Author: Bernie Pope+Maintainer: Bernie Pope <florbitous@gmail.com>+Stability: Experimental+category: Language +Build-type: Simple+Cabal-version: >=1.8+Description: Read and pretty print Python bytecode (.pyc) files.++source-repository head+ type: git+ location: git://github.com/bjpop/blip.git++Executable readpyc {+ ghc-options: -Wall -fno-warn-name-shadowing -fno-warn-orphans+ main-is: Main.hs+ hs-source-dirs: src+ build-depends:+ base==4.*,+ bliplib==0.1.*,+ parseargs==0.1.*+}
+ src/Main.hs view
@@ -0,0 +1,81 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main +-- Copyright : (c) 2012, 2013 Bernie Pope+-- License : BSD-style+-- Maintainer : florbitous@gmail.com+-- Stability : experimental+-- Portability : ghc+--+-- A program to read and pretty print a Python bytecode file (.pyc file).+--+-----------------------------------------------------------------------------++module Main where++import System.Exit (ExitCode (..), exitWith)+import System.IO (openFile, IOMode(..), hClose)+import Control.Monad (when)+import System.Console.ParseArgs+ (Argtype (..), argDataOptional, Arg (..)+ , gotArg, getArg, parseArgsIO, ArgsComplete (..), Args(..))+import Blip.Version (versionString)+import Blip.Marshal (readPyc)+import Blip.Pretty (prettyString)++data ArgIndex+ = Help+ | InputFile+ | Version+ deriving (Eq, Ord, Show)++help :: Arg ArgIndex+help =+ Arg+ { argIndex = Help+ , argAbbr = Just 'h'+ , argName = Just "help"+ , argData = Nothing+ , argDesc = "Display a help message."+ }++inputFile :: Arg ArgIndex+inputFile =+ Arg+ { argIndex = InputFile+ , argAbbr = Nothing+ , argName = Nothing+ , argData = argDataOptional "input file" ArgtypeString+ , argDesc = "Name of the input Python file."+ }++version :: Arg ArgIndex+version =+ Arg+ { argIndex = Version+ , argAbbr = Nothing+ , argName = Just "version"+ , argData = Nothing+ , argDesc = "Show the version number of readpyc."+ }++getInputFile :: Args ArgIndex -> Maybe FilePath+getInputFile argMap = getArg argMap InputFile ++main :: IO ()+main = do+ let args = [version, help, inputFile]+ argMap <- parseArgsIO ArgsComplete args+ when (gotArg argMap Help) $ do+ putStrLn $ argsUsage argMap+ exitWith ExitSuccess+ when (gotArg argMap Version) $ do+ putStrLn $ "readpyc version " ++ versionString+ exitWith ExitSuccess+ case getInputFile argMap of+ Nothing -> return ()+ Just inFile -> do+ handle <- openFile inFile ReadMode+ pycFile <- readPyc handle+ putStrLn $ prettyString pycFile+ hClose handle