Exemple #1
0
 def test_mkdirs(self):
     mkdirs('spam.eggs')
     self.assertEqual(self._dentries(), [])
     for _ in range(2):
         mkdirs('spam/eggs/spam.eggs')
         self.assertEqual(self._dentries(), [(False, 'spam'),
                                             (False, 'spam/eggs')])
    def save(self, filename=None, directory=None):
        """Save the DOT source to file. Ensure the file ends with a newline.

        Args:
            filename: Filename for saving the source (defaults to ``name`` + ``'.gv'``)
            directory: (Sub)directory for source saving and rendering.
        Returns:
            The (possibly relative) path of the saved source file.
        """
        if filename is not None:
            self.filename = filename
        if directory is not None:
            self.directory = directory

        filepath = self.filepath
        tools.mkdirs(filepath)

        data = text_type(self.source)

        with codecs.open(filepath, 'w', encoding=self.encoding) as fd:
            fd.write(data)
            if not data.endswith(u'\n'):
                fd.write(u'\n')

        return filepath
Exemple #3
0
def _run_batch(opts, **kwargs):
    input_paths = opts['<input-path>'] or ['.']
    output_folder = opts['-O']
    log.info("Processing %r --> %r...", input_paths, output_folder)
    input_paths = file_finder(input_paths)
    if not input_paths:
        raise CmdException("No <input-path> found! \n"
                           "\n  Try: co2mpas batch <fpath-1>..."
                           "\n  or : co2mpas gui"
                           "\n  or : co2mpas --help")

    if not osp.isdir(output_folder):
        if opts['--force']:
            from graphviz.tools import mkdirs
            if not ''.endswith('/'):
                output_folder = '%s/' % output_folder
            mkdirs(output_folder)
        else:
            raise CmdException("Specify a folder for "
                               "the '-O %s' option!" % output_folder)

    _init_defaults(opts['--modelconf'])

    kw = {
        'variation': parse_overrides(opts['--override']),
        'overwrite_cache': opts['--overwrite-cache'],
        'modelconf': opts['--modelconf']
    }
    kw.update(kwargs)

    from co2mpas.batch import process_folder_files
    process_folder_files(input_paths, output_folder, **kw)
Exemple #4
0
def test_mkdirs(tmp_path):
    with utils.as_cwd(tmp_path):
        mkdirs('spam.eggs')
        assert list(itertree(str(tmp_path))) == []
        for _ in range(2):
            mkdirs('spam/eggs/spam.eggs')
            assert list(itertree(str(tmp_path))) == [(False, 'spam'),
                                                     (False, 'spam/eggs')]
Exemple #5
0
def test_mkdirs(tmpdir):
    with tmpdir.as_cwd():
        mkdirs('spam.eggs')
        assert list(itertree(str(tmpdir))) == []
        for _ in range(2):
            mkdirs('spam/eggs/spam.eggs')
            assert list(itertree(str(tmpdir))) == [(False, 'spam'),
                                                   (False, 'spam/eggs')]
Exemple #6
0
def _cmd_modelconf(opts):
    output_folder = opts['-O']
    if not osp.isdir(output_folder):
        if opts['--force']:
            from graphviz.tools import mkdirs
            if not ''.endswith('/'):
                output_folder = '%s/' % output_folder
            mkdirs(output_folder)
        else:
            raise CmdException("Specify a folder for "
                               "the '-O %s' option!" % output_folder)
    import datetime
    fname = datetime.datetime.now().strftime('%Y%m%d_%H%M%S-conf.yaml')
    fname = osp.join(output_folder, fname)
    defaults = _init_defaults(opts['--modelconf'])
    defaults.dump(fname)
    log.info('Default model config written into yaml-file(%s)...', fname)
Exemple #7
0
def _run_batch(opts):
    input_paths = opts['<input-path>']
    output_folder = opts['-O']
    if opts['--gui']:
        input_paths = [
            _prompt_folder(folder_name='INPUT',
                           fpath=input_paths[-1] if input_paths else None)
        ]
        output_folder = _prompt_folder(folder_name='OUTPUT',
                                       fpath=output_folder)
        opts.update(_prompt_options(opts))

    log.info("Processing %r --> %r...", input_paths, output_folder)
    input_paths = file_finder(input_paths)
    if not input_paths:
        raise CmdException("No <input-path> found! \n"
                           "\n  Try: co2mpas batch <fpath-1>..."
                           "\n  or : co2mpas --gui"
                           "\n  or : co2mpas --help")

    if not osp.isdir(output_folder):
        if opts['--force']:
            from graphviz.tools import mkdirs
            if not ''.endswith('/'):
                output_folder = '%s/' % output_folder
            mkdirs(output_folder)
        else:
            raise CmdException("Specify a folder for "
                               "the '-O %s' option!" % output_folder)

    from co2mpas.batch import process_folder_files
    process_folder_files(input_paths,
                         output_folder,
                         with_output_file=not opts['--only-summary'],
                         plot_workflow=opts['--plot-workflow'],
                         output_template=opts['--out-template'],
                         overwrite_cache=opts['--overwrite-cache'],
                         soft_validation=opts['--soft-validation'])
Exemple #8
0
 def test_mkdirs_invalid(self):
     with open('spam.eggs', 'wb'):
         pass
     with self.assertRaises(OSError):
         mkdirs('spam.eggs/spam')
Exemple #9
0
def test_mkdirs_invalid(tmp_path):
    with utils.as_cwd(tmp_path):
        (tmp_path / 'spam.eggs').write_bytes(b'')
        with pytest.raises(OSError):
            mkdirs('spam.eggs/spam')
Exemple #10
0
 def test_file(self):
     with self.assertRaises(OSError):
         mkdirs('setup.py/spam')
Exemple #11
0
 def test_cwd(self):
     dirnames = self._dirnames()
     mkdirs('setup.py')
     self.assertEqual(self._dirnames(), dirnames)
Exemple #12
0
 def test_file(self):
     with self.assertRaises(OSError):
         mkdirs('setup.py/spam')
Exemple #13
0
 def test_cwd(self):
     dirnames = self._dirnames()
     mkdirs('setup.py')
     self.assertEqual(self._dirnames(), dirnames)
Exemple #14
0
def test_mkdirs_invalid(tmpdir):
    with tmpdir.as_cwd():
        (tmpdir / 'spam.eggs').write_binary(b'')
        with pytest.raises(OSError):
            mkdirs('spam.eggs/spam')
Exemple #15
0
def test_mkdirs_invalid(tmpdir):
    with tmpdir.as_cwd():
        tmpdir.join('spam.eggs').write(b'')
        with pytest.raises(OSError):
            mkdirs('spam.eggs/spam')