def cleanup_pipe(): d6tpipe.api.ConfigManager(profile=cfg['d6tpipe_profile']).init( {'filerepo': 'tests/d6tpipe-files1/'}, reset=True) api1 = d6tpipe.APIClient(profile=cfg['d6tpipe_profile']) api1.login(cfg['d6tpipe_username'], cfg['d6tpipe_password']) # d6tpipe.api.create_pipe_with_remote(api, {'name': cfg['d6tpipe_pipe1'], 'protocol': 'd6tfree'}) # settings = {"user":cfg['d6tpipe_username2'],"role":"read"} # d6tpipe.create_or_update_permissions(api1, cfg['d6tpipe_pipe1'], settings) pipe1 = d6tpipe.Pipe(api1, cfg['d6tpipe_pipe1']) pipe1.delete_files_local(confirm=False, delete_all=True) d6tpipe.api.ConfigManager(profile=cfg['d6tpipe_profile2']).init( {'filerepo': 'tests/d6tpipe-files2/'}, reset=True) api2 = d6tpipe.APIClient(profile=cfg['d6tpipe_profile2']) api2.login(cfg['d6tpipe_username2'], cfg['d6tpipe_password2']) # d6tpipe.api.create_pipe_with_remote(api2, {'name': cfg['d6tpipe_pipe2'], 'protocol': 'd6tfree'}) pipe12 = d6tpipe.Pipe(api2, cfg['d6tpipe_pipe1']) pipe2 = d6tpipe.Pipe(api2, cfg['d6tpipe_pipe2']) pipe12.delete_files_local(confirm=False, delete_all=True) pipe2.delete_files_local(confirm=False, delete_all=True) yield api1, api2 @fuckit def delhelper(): pipe1.delete_files_local(confirm=False, delete_all=True) pipe12.delete_files_local(confirm=False, delete_all=True) pipe2.delete_files_local(confirm=False, delete_all=True) delhelper()
def init(default_pipe_name, profile=None, local_pipe=False, local_api=False, reset=False, api=None, set_dir=True, api_args=None, pipe_args=None): """ Initialize d6tpipe Args: default_pipe_name (str): name of pipe to store results. Override by setting Task.pipe attribute profile (str): name of d6tpipe profile to get api if api not provided local_pipe (bool): use `PipeLocal()` local_api (bool): use `APILocal()` reset (bool): reset api and pipe connection api (obj): d6tpipe api object. if not provided will be loaded set_dir (bool): if True, set d6tflow directory to default pipe directory api_args (dir): arguments to pass to api pipe_args (dir): arguments to pass to pipe """ if not d6tflow.settings.isinitpipe or reset: d6tflow.cache.pipe_default_name = default_pipe_name api_args = {} if api_args is None else api_args pipe_args = {} if pipe_args is None else pipe_args if local_pipe: pipe_ = d6tpipe.PipeLocal(default_pipe_name, profile=profile) else: if api is None: if local_api: d6tflow.cache.api = d6tpipe.APILocal(profile=profile, **api_args) else: d6tflow.cache.api = d6tpipe.APIClient(profile=profile, **api_args) else: d6tflow.cache.api = api pipe_ = d6tpipe.Pipe(d6tflow.cache.api, default_pipe_name, **pipe_args) d6tflow.cache.pipes[default_pipe_name] = pipe_ if set_dir: d6tflow.settings.isinitpipe = False d6tflow.set_dir(pipe_.dir) d6tflow.settings.isinitpipe = True
import d6tpipe #**************************** # vendor #**************************** api = d6tpipe.APIClient(profile='d6tdev') d6tpipe.upsert_pipe(api,{'name':'demo-vendor'}) pipe = d6tpipe.Pipe(api, 'demo-vendor') print(pipe.settings['options']['remotepath']) import pandas as pd df = pd.DataFrame({'date':range(10),'data':range(10)}) df.to_csv(pipe.dirpath/'monthly-201901.csv') df.to_csv(pipe.dirpath/'daily-201901.csv') pipe.setmode('all') pipe.push_preview() pipe.push() # create subscription levels d6tpipe.upsert_pipe(api,{'name':'demo-vendor-daily','parent':'demo-vendor','options':{'include':'*daily*.csv'}}) d6tpipe.upsert_pipe(api,{'name':'demo-vendor-monthly','parent':'demo-vendor','options':{'include':'*monthly*.csv'}}) #**************************** # client permissions #**************************** d6tpipe.api.ConfigManager(profile='demo').init() # use demo account api2 = d6tpipe.api.APIClient(profile='demo')
import d6tpipe cfg_local = False #**************************** # vendor #**************************** if not cfg_local: api = d6tpipe.APIClient(profile='d6tdev') else: d6tpipe.api.ConfigManager(profile='d6tdev-local').update({'token':'a0cefc11ec9b2d6a44f7e360d6ea36d494679f8c'}) api = d6tpipe.APIClient(profile='d6tdev-local')#,token=None) api.login() d6tpipe.upsert_pipe(api,{'name':'demo-vendor'}) pipe = d6tpipe.Pipe(api, 'demo-vendor') print(pipe.settings['options']['remotepath']) print(pipe._get_credentials()) import pandas as pd df = pd.DataFrame({'date':range(10),'data':range(10)}) df.to_csv(pipe.dirpath/'monthly-201901.csv') df.to_csv(pipe.dirpath/'daily-201901.csv') pipe.setmode('all') pipe.push_preview() pipe.push() # create subscription levels d6tpipe.upsert_pipe(api,{'name':'demo-vendor-daily','parent':'demo-vendor','options':{'include':'*daily*.csv'}}) d6tpipe.upsert_pipe(api,{'name':'demo-vendor-monthly','parent':'demo-vendor','options':{'include':'*monthly*.csv'}})
def getapi(local=False, profile=cfg_profile, filecfg=cfg_cfgfname): if local: return d6tpipe.APILocal(profile=profile, filecfg=filecfg) else: return d6tpipe.APIClient(profile=profile, filecfg=filecfg)
import d6tpipe api = d6tpipe.APIClient(profile='utest-local') api = d6tpipe.APIClient(profile='utest-d6tdev') api = d6tpipe.APIClient(profile='utest-dev', filecfg='~/d6tpipe/cfg-utest-dev.json') api2 = d6tpipe.APIClient(profile='utest-dev2', filecfg='~/d6tpipe/cfg-utest-dev.json')