Exemplo n.º 1
0
def main(argv):
    parser = argparse.ArgumentParser(description='Copy DCP via FTP')
    parser.add_argument('dir_path',
        metavar='DIRECTORY_PATH',
        type = str,
        help = 'directory to copy / mirror ' )
    parser.add_argument('-d', '--debug', dest='debug', action='store_const',
        const=logging.DEBUG, default=logging.INFO,
        help='debug mode')
    parser.add_argument('-c', '--config',
        type = str,
        default = CONFIG_FILE,
        help='path to config file')
    parser.add_argument('-x', '--dry-run',
        type = bool,
        help='run ftp in dry run mode')



    args = parser.parse_args()

    try :
        config_data = parseConfig(args.config)
    except ValueError as err:
        msg = "JSON parse ERROR {}".format(err)
        logger.error(msg)
        return 1

    if not os.path.exists(args.dir_path):
        _err = "path {} does not exists".format(args.dir_path)
        logging.error(_err)
        return 1

    if 'ftp-library' in config_data and config_data['ftp-library'] == True :
        _dir_path = os.path.abspath(args.dir_path)
        try:

            ftp = Lftp(_dir_path, config_data)
            ftp.mirror()
        except TdcpbException as err :
            #smoething goes wrong in copy
            logger.error("FTP transfer FAIL: {}".format(err))
        else:
            logger.info("FTP transfer OK")
Exemplo n.º 2
0
def pyx_to_dll_wrapper(filename, ext=None, force_rebuild=0, build_in_temp=False, pyxbuild_dir=None, setup_args={}, reload_support=False):
    """
    compila il file .pyx passato; ha la stessa signature della funzione
    pyximport.pyx_to_dll ma utilizza, se presente, il file build.cfg posto
    nella stessa directory del file .pyx.

    il file .cfg deve definire un dizionario "cython" con, opzionale, una
    chiave per ogni file .pyx, esempio:

    cython = {
        'foo': {
        }
    }

    Il dizionario associato a 'foo' verrà utilizzato per la compilazione del
    file foo.pyx; questo dizionario può contenere le seguenti chiave:

        * include_dirs
        * library_dirs
        * libraries

    che hanno lo stesso significato dei corrispettivi argomenti nella classe
    distutils.core.Extension

        http://docs.python.org/distutils/apiref.html#distutils.core.Extension

    unica differenza, include_dirs viene utilizzato anche da cython come elenco
    di path dove cercare eventuali .pxd

    la configurazione di un modulo può essere specificata per le varie
    piattaforme dove verrà compilato aggiungendo ad ogni attributo i suffissi:
    _linux, _nt, _darwin

    Per ogni attributo possono essere presenti sia la versione specifica per la
    piattaforma che quella generica, in questo caso i due valori vengono
    concatenati:

    cython = {
        'foo': {
            'include_dirs': ('/usr/include',),
            'include_dirs_linux': ('/usr/local/include',),
        }
    }

    Le directory presenti in `lib_dir`/pxd/ vengono aggiunte automaticamente al
    path di ricerca di cython *e* alle include_dirs passate al compilatore, in
    questo modo possiamo avere in un solo posto i file .pxd insieme ai file .h
    necessari a cython.
    """
    from distutils.extension import Extension
    try:
        from pyximport.pyxbuild import pyx_to_dll
    except TypeError: # unsupported operand type(s) for +: 'NoneType' and 'str'
        # Questo è un workaround per una incompatibilità con python -O
        # dell'estensione a distutils di cython che cerca fare
        # Extension.__doc__ + "altra documentazione", solo
        # che con l'ottimizzazione accesa Extension.__doc__ è None.
        assert Extension.__doc__ is None
        Extension.__doc__ = ""
        from pyximport.pyxbuild import pyx_to_dll

    if not pxd_include_dirs:
        pxd_include_dirs.extend(x for x in glob(os.path.join(common.opts.libs, 'pxd', '*')) if os.path.isdir(x))

    cfgpath = os.path.join(os.path.dirname(filename), 'build.cfg')
    modname = os.path.splitext(os.path.basename(filename))[0]
    cfg = common.parseConfig(cfgpath).get('cython', {})
    conf = Conf(cfg.get(modname, {}))

    if ext is None:
        # il nome dell'estensione deve essere un dotted name relativo alla
        # directory dei sorgenti
        name = os.path.normpath(filename)[len(common.opts.source):]
        if name[0] in '/\\':
            name = name[1:]
        name = os.path.splitext(name)[0].replace('/', '.').replace('\\', '.')
        ext = Extension(name=name, sources=[filename])

    include_dirs = pxd_include_dirs + ( conf['include_dirs'] or [] )
    library_dirs = conf['library_dirs'] or []
    libraries = conf['libraries'] or []

    def _s(name, value):
        if hasattr(ext, name):
            setattr(ext, name, getattr(ext, name) + value)
        else:
            setattr(ext, name, value)

    _s('pyrex_include_dirs', pxd_include_dirs)
    _s('include_dirs', include_dirs)
    _s('library_dirs', library_dirs)
    _s('libraries', libraries)

    return pyx_to_dll(
        filename,
        ext=ext,
        force_rebuild=True,
        build_in_temp=build_in_temp,
        pyxbuild_dir=pyxbuild_dir,
        setup_args=setup_args,
        reload_support=reload_support,
    )
Exemplo n.º 3
0
if __name__ == '__main__':
    
    # Parsing command line arguments
    (options, args) = parseOptions()
    
    common.log('Starting TorScanner at %s UTC...' % \
               time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()), 'CMD')
    
    #Joining cmdline param 'config' and list of default places
    cfgs = []
    if options.config: cfgs.extend([options.config])
    cfgs.extend(CONFIG_PATHS)

    # Loading configuration file
    config = common.parseConfig(cfgs, CONFIG_DEFAULTS)
        
    #Joining cmdline param 'data' and list of default datadir places
    datadirs = []
    if options.data: datadirs.extend([options.data])
    datadirs.extend(DATADIR_PATHS)

    # Selecting data directory. Will create in user directory, 
    # if there is no other location accessible for writing.
    try:
        datadir = common.selectDatadir(datadirs)
    except Exception, e:
        # When no datadir exists or exists without write access
        common.log(e, 'ERROR')
        common.log("Creating new data directory in '%s'" % DATADIR_USER )
        try:
Exemplo n.º 4
0
if __name__ == '__main__':

    # Parsing command line arguments
    (options, args) = parseOptions()

    common.log('Starting TorScanner at %s UTC...' % \
               time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()), 'CMD')

    #Joining cmdline param 'config' and list of default places
    cfgs = []
    if options.config: cfgs.extend([options.config])
    cfgs.extend(CONFIG_PATHS)

    # Loading configuration file
    config = common.parseConfig(cfgs, CONFIG_DEFAULTS)

    #Joining cmdline param 'data' and list of default datadir places
    datadirs = []
    if options.data: datadirs.extend([options.data])
    datadirs.extend(DATADIR_PATHS)

    # Selecting data directory. Will create in user directory,
    # if there is no other location accessible for writing.
    try:
        datadir = common.selectDatadir(datadirs)
    except Exception, e:
        # When no datadir exists or exists without write access
        common.log(e, 'ERROR')
        common.log("Creating new data directory in '%s'" % DATADIR_USER)
        try: