Exemplo n.º 1
0
    def __init__(self, point: DatePoint):
        super(RawStreamRequest, self).__init__(point=point)
        self.url = point.url
        assure_dir(point.dst_dir)
        self.dst_dir = point.dst_dir

        self.dst_file = os.path.join(self.dst_dir, self.FILENAME)
Exemplo n.º 2
0
def download(ctx: click.Context, kind: str, mode: str, dst_dir: str) -> None:
    if kind == 'kline':
        kline_transform = BitMexKlineTransform(dst_dir, dst_dir)
        kline_transform.do_all()
        kline_fullfill = KlineFullFill(dst_dir)
        kline_fullfill.do_all()
    else:
        assure_dir(dst_dir)
        b = BitMexDownloader(kind, mode, dst_dir)
        b.do_all()
Exemplo n.º 3
0
    def __init__(self, point: DatePoint):
        super(_HDFStream, self).__init__(point=point)
        self.url = point.url
        assure_dir(point.dst_dir)
        self.dst_dir = point.dst_dir

        if self.kind == 'trade':
            self.dst_file = os.path.join(self.dst_dir, TRADE_FILE_NAME)
        elif self.kind == 'quote':
            self.dst_file = os.path.join(self.dst_dir, QUOTE_FILE_NAME)
        self.process_point = point

        self.processed_key: Set = set()
Exemplo n.º 4
0
def startstrategy(ctx: click.Context, name: str, directory: str) -> None:
    directory = os.path.abspath(directory)
    assert os.path.isdir(directory), _(
        'You have to provide an exist directory')
    template_dir = os.path.join(monkq.__path__[0], 'config',
                                'project_template')  # type: ignore
    target_dir = os.path.join(directory, name)
    if os.path.exists(target_dir):
        raise CommandError(_("The project name has already been used"))
    assure_dir(target_dir)
    prefix_length = len(template_dir) + 1

    for root, dirs, files in os.walk(template_dir):
        relative_dir = root[prefix_length:]
        if relative_dir:
            create_dir = os.path.join(target_dir, relative_dir)
            if not os.path.exists(create_dir):
                os.mkdir(create_dir)

        for dirname in dirs[:]:
            if dirname.startswith('.') or dirname == '__pycache__':
                dirs.remove(dirname)

        for filename in files:
            if filename.endswith(('.pyo', '.pyc')):
                # Ignore some files as they cause various breakages.
                continue

            old_path = os.path.join(root, filename)

            if filename.endswith(('.py-tpl')):
                filename = filename.replace('.py-tpl', '.py')
                filename = filename.replace('@name@', name)
                new_path = os.path.join(target_dir, relative_dir, filename)
                with open(old_path) as template_f:
                    content = template_f.read()
                content = content.replace("@name@", name)
                with open(new_path, 'w') as new_file:
                    new_file.write(content)
            else:
                new_path = os.path.join(target_dir, relative_dir, filename)
                shutil.copyfile(old_path, new_path)
            shutil.copymode(old_path, new_path)
            make_writable(new_path)
Exemplo n.º 5
0
def test_assure_home() -> None:
    tmp_dir = tempfile.gettempdir()
    assert assure_dir(tmp_dir)

    with tempfile.NamedTemporaryFile() as f:
        with pytest.raises(NotADirectoryError):
            assure_dir(f.name)

    with tempfile.TemporaryDirectory() as tmp:
        assert assure_dir(tmp)

        new_p = os.path.join(tmp, 't/w')

        assert not assure_dir(new_p)

        assert assure_dir(new_p)