Ejemplo n.º 1
0
 def access():
     opt = CLI.parse(argv)
     level = logging.DEBUG if opt['--debug'] else logging.INFO
     logging.basicConfig(level=level)
     return CLI(environ,
                openrd=lambda n: openf(n),
                arguments=opt,
                SMTP=DrySMTP if opt['--dry-run'] else smtplib.SMTP)
Ejemplo n.º 2
0
    def __init__(self, ops, path):
        (openf, ) = ops
        self.setBytes = lambda bs: openf(path, 'w').write(bs)

        def descendant(sub):
            d = path_join(path, sub)
            if not d.startswith(path):
                raise IOError('%s not under %s', d, path)
            return d

        self.subEdFile = lambda sub: Editable(ops, descendant(sub))
Ejemplo n.º 3
0
    def __init__(self, ops, path):
        (openf, ) = ops
        self.setBytes = lambda bs: openf(path, 'w').write(bs)

        def descendant(sub):
            d = path_join(path, sub)
            if not d.startswith(path):
                raise IOError('%s not under %s', d, path)
            return d

        self.subEdFile = lambda sub: Editable(ops, descendant(sub))
Ejemplo n.º 4
0
    def _privileged_main():
        from __builtin__ import open as openf
        from gzip import GzipFile
        from os import environ, rename, rmdir
        from os.path import exists
        from sqlite3 import connect
        from sys import argv, stdin, stdout
        from zipfile import ZipFile
        import warnings

        from redcap import Project

        mkTeam = DevTeams.maker(lambda n: openf(n, 'w'))
        with warnings.catch_warnings():
            warnings.filterwarnings("once")
            main(argv, stdin, stdout,
                 checkDB=mkCheckDB(exists, connect),
                 unzip=mkUnzip(lambda f: ZipFile(f, 'r'),
                               rename, rmdir),
                 gunzip=mkGunzip(GzipFile, lambda n: openf(n, 'wb')),
                 mkTeam=mkTeam,
                 projectAccess=mkProjectAccess(Project, environ))
Ejemplo n.º 5
0
    def _privileged_main():
        from __builtin__ import open as openf
        from gzip import GzipFile
        from os import environ, rename, rmdir
        from os.path import exists
        from sqlite3 import connect
        from sys import argv, stdin, stdout
        from zipfile import ZipFile
        import warnings

        from redcap import Project

        mkTeam = DevTeams.maker(lambda n: openf(n, 'w'))
        with warnings.catch_warnings():
            warnings.filterwarnings("once")
            main(argv,
                 stdin,
                 stdout,
                 checkDB=mkCheckDB(exists, connect),
                 unzip=mkUnzip(lambda f: ZipFile(f, 'r'), rename, rmdir),
                 gunzip=mkGunzip(GzipFile, lambda n: openf(n, 'wb')),
                 mkTeam=mkTeam,
                 projectAccess=mkProjectAccess(Project, environ))
    def get_config():
        [config_fn, pid] = argv[1:3]

        config = configparser.SafeConfigParser()
        config_fp = openf(config_fn)
        config.readfp(config_fp, filename=config_fn)

        api_url = config.get('api', 'api_url')
        verify_ssl = config.getboolean('api', 'verify_ssl')
        log.debug('API URL: %s', api_url)

        bs_token = config.get(pid, 'bootstrap_token')
        log.debug('bootstrap token: %s...%s', bs_token[:4], bs_token[-4:])
        bs_proj = Project(api_url, bs_token, verify_ssl=verify_ssl)
        data_token = config.get(pid, 'data_token')
        data_proj = Project(api_url, data_token, verify_ssl=verify_ssl)

        def open_dest(file_name, file_format):
            file_dest = config.get(pid, 'file_dest')
            return openf(
                os_path.join(file_dest, file_name + '.' + file_format), 'wb')

        return pid, bs_proj, data_proj, open_dest
Ejemplo n.º 7
0
 def open_config():
     _plugin, path = argv[1:3]
     return openf(path, 'r+b')
 def open_dest(file_name, file_format):
     file_dest = config.get(pid, 'file_dest')
     return openf(
         os_path.join(file_dest, file_name + '.' + file_format), 'wb')
Ejemplo n.º 9
0
 def sub_rd(n):
     if not n.isdigit():
         raise IOError('not a device number: ' + n)
     return Rd(path + n, sub_rd=_cannot,
               open_rd=lambda: openf(path + n))
Ejemplo n.º 10
0
 def getRecords(_, opt):
     with openf(opts[opt]) as infp:
         return relation.readRecords(infp)