コード例 #1
0
ファイル: publish.py プロジェクト: xphenomenon/pycse
def publish(args):
    '''args is one of two things:
    1. a string from an ipython magic method
    2. the output from argparse
    '''
    global data,user_data_string
    
    if isinstance(args, unicode):
        # magic method provides a unicode string.
        # we have to parse the string
        args = parser.parse_args(args.split())

    INPUT = args.files[0]
        
    if args.no_user:
        user_data_string = False
        for prop in PROPERTIES:
            data[prop] = None
        
        name, ext = os.path.splitext(INPUT)
        BASENAME = name
    else:
        # check for compliance of data
        with open(INPUT) as f:
            text = f.read()

            for prop in PROPERTIES:
                regexp = '#\+{0}:(.*)'.format(prop)
                m = re.search(regexp, text)
                if m:
                    data[prop] = m.group(1).strip()
                else:
                    raise Exception('''You are missing #+{0}: in your file. please add it and try again.'''.format(prop))

        BASENAME = '{ANDREWID}-{COURSE}-{ASSIGNMENT}'.format(**data)
        
    myoptions = ['-l', #allow LaTeX literal comment
                 '-e', #allow LaTeX math mode escape in code wih dollar signs
                 ]
    
    if args.v:
        myoptions += ['-v']

    if args.tex:
        myoptions += ['-t', 'tex']
        myoptions += ['-o','{0}'.format(BASENAME),]
    else:
        myoptions += ['-o','{0}'.format(BASENAME),]

    opts, args = options.parse_options(myoptions)

    opts.update({'infilename':INPUT})

    default_options, _not_used = options.option_parser.parse_args(args =[])
    default_options.figure_type = 'png'

    pyreport.main(open(INPUT), overrides=opts)

    try:
        os.startfile(BASENAME + '.pdf')
    except:
        pass
コード例 #2
0
ファイル: test_options.py プロジェクト: svenk/pyreport
def test_parse_options():
    assert_equal(options.parse_options([]), ({}, []) )
    assert_equal(options.parse_options(['foo']), ({}, ['foo']) )
    assert_equal(options.parse_options(['-t','foo']), 
                            ({'outtype': 'foo'}, []) )
コード例 #3
0
def publish(args):
    '''args is one of two things:
    1. a string from an ipython magic method
    2. the output from argparse
    '''
    global data, user_data_string

    if isinstance(args, unicode):
        # magic method provides a unicode string.
        # we have to parse the string
        args = parser.parse_args(args.split())

    INPUT = args.files[0]

    if args.no_user:
        user_data_string = False
        for prop in PROPERTIES:
            data[prop] = None

        name, ext = os.path.splitext(INPUT)
        BASENAME = name
    else:
        # check for compliance of data
        with open(INPUT) as f:
            text = f.read()

            for prop in PROPERTIES:
                regexp = '#\+{0}:(.*)'.format(prop)
                m = re.search(regexp, text)
                if m:
                    data[prop] = m.group(1).strip()
                else:
                    raise Exception(
                        '''You are missing #+{0}: in your file. please add it and try again.'''
                        .format(prop))

        BASENAME = '{ANDREWID}-{COURSE}-{ASSIGNMENT}'.format(**data)

    myoptions = [
        '-l',  #allow LaTeX literal comment
        '-e',  #allow LaTeX math mode escape in code wih dollar signs
    ]

    if args.v:
        myoptions += ['-v']

    if args.tex:
        myoptions += ['-t', 'tex']
        myoptions += [
            '-o',
            '{0}'.format(BASENAME),
        ]
    else:
        myoptions += [
            '-o',
            '{0}'.format(BASENAME),
        ]

    opts, args = options.parse_options(myoptions)

    opts.update({'infilename': INPUT})

    default_options, _not_used = options.option_parser.parse_args(args=[])
    default_options.figure_type = 'png'

    pyreport.main(open(INPUT), overrides=opts)

    # clean up
    for fname in ['md.djs']:
        if os.path.exists(fname):
            os.unlink(fname)

    try:
        os.startfile(BASENAME + '.pdf')
    except:
        pass