Ejemplo n.º 1
0
    def test_refs_multi(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc_ref_multi', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_content = [
                ('.guides/content/computer-programming.md',
                 'Computer programming content'),
                ('.guides/content/computer-programming-what-is-a-computer-.md',
                 'What is a computer? content'),
                ('.guides/content/what-is-programming-.md',
                 'What is programming? content\n\n0 in section Declaring variables'
                 ),
                ('.guides/content/what-is-programming-variables-and-operators.md',
                 'Variables and operators content 2'),
                ('.guides/content/assigning-variables.md',
                 'Assigning variables content\n\n0.1 in section Assigning variables'
                 )
            ]

            for path, content in check_content:
                file_content = load_file(generate.joinpath(path))
                self.assertEqual(content, file_content)
Ejemplo n.º 2
0
    def test_convert_transformations(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc4', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_content = [
                ('.guides/content/computer-programming.md',
                 'My simple text\n\nComputer programming content'),
                ('.guides/content/computer-programming-what-is-a-computer-.md',
                 'What is a computer? content'),
                ('.guides/content/computer-programming-what-is-programming-.md',
                 ''),
                ('.guides/content/variables-and-operators.md',
                 'Variables and operators content'),
                ('.guides/content/variables-and-operators-assigning-variables.md',
                 'Assigning variables content'),
                ('.guides/content/variables-and-operators-declaring-variables.md',
                 'Declaring variables content')
            ]

            for path, content in check_content:
                file_content = load_file(generate.joinpath(path))
                self.assertEqual(content, file_content)
Ejemplo n.º 3
0
    def test_convert_assets(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc1', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_exists = [
                'figs/CPU.jpg', 'figs/meld.png', 'code/GuessSoln.java',
                '.guides/book.json', '.guides/metadata.json',
                '.guides/content/computer-programming.md',
                '.guides/content/computer-programming-what-is-a-computer-.md',
                '.guides/content/computer-programming-what-is-programming-.md',
                '.guides/content/variables-and-operators.md',
                '.guides/content/variables-and-operators-assigning-variables.md',
                '.guides/content/variables-and-operators-declaring-variables.md'
            ]

            for path in check_exists:
                check = generate.joinpath(path)
                self.assertTrue(check.exists())

            check_not_exists = ['figs/aliasing.pdf', 'figs/circle.fig']

            for path in check_not_exists:
                check = generate.joinpath(path)
                self.assertFalse(check.exists())
Ejemplo n.º 4
0
 def convert_schedule(self):
     try:
         QtWidgets.QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)
         cvt.convert(self.ui.fileNameEdit.text(), self.ui.sheetSelector.currentText(), self.ui.templateFileNameEdit.text())
     except Exception as e:
         print('Ошибка:\n', traceback.format_exc())
         sys.exit(app.exec())
     finally:
         QtWidgets.QApplication.restoreOverrideCursor()
Ejemplo n.º 5
0
    def test_codio_section(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc7', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_exists = [
                'code/GuessSoln.java', '.guides/book.json',
                '.guides/metadata.json',
                '.guides/content/computer-programming.md',
                '.guides/content/computer-programming-what-is-programming-.md',
                '.guides/content/variables-and-operators.md',
                '.guides/content/variables-and-operators-assigning-variables.md',
                '.guides/content/variables-and-operators-declaring-variables.md',
                '.guides/content/computer-programming-what-is-a-computer-.md'
            ]

            for path in check_exists:
                check = generate.joinpath(path)
                self.assertTrue(check.exists(), check)

            book_raw = load_file(generate.joinpath('.guides/book.json'))
            book = json.loads(book_raw)

            children = book.get('children')
            self.assertEqual(2, len(children))

            cp = children[0]

            self.assertEqual(cp.get('id'), 'computer-programming')
            self.assertEqual(cp.get('pageId'), 'computer-programming')
            self.assertEqual(cp.get('type'), 'chapter')
            self.assertEqual(cp.get('title'), 'Computer programming')

            cp_children = cp.get('children')

            self.assertEqual(1, len(cp_children))

            wp = cp_children[0]['children'][0]

            self.assertEqual(wp.get('id'),
                             'computer-programming-what-is-programming-')
            self.assertEqual(wp.get('pageId'),
                             'computer-programming-what-is-programming-')
            self.assertEqual(wp.get('type'), 'page')
            self.assertEqual(wp.get('title'), 'What is programming?')

            metadata_raw = load_file(
                generate.joinpath('.guides/metadata.json'))
            metadata = json.loads(metadata_raw)

            sections = metadata.get('sections')
            self.assertEqual(6, len(sections))
Ejemplo n.º 6
0
    def test_convert_metadata(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc2', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            metadata_raw = load_file(
                generate.joinpath('.guides/metadata.json'))
            metadata = json.loads(metadata_raw)

            self.assertTrue(metadata.get('hideMenu'))
            self.assertTrue(metadata.get('protectLayout'))
def index():
    #POST
    if request.method == 'POST':
        file = request.files['file']
        if file and allowed_file(file.filename):
            filename = 'input.csv' #secure_filename(file.filename)
            workspace, uid = make_workspace()
            filepath = os.path.join(workspace, filename)
            file.save(filepath)
            ret = uid
            try:
                data, size, input_file = ingest(filepath, 'none')
                converted_file, log = convert(workspace, filename, request)
                ret = render_template('task_complete.html', log = log,  task_id = uid, )
                return ret
            except Exception as e:
                panicfile = os.path.join(workspace, "panic.log")
                with open(panicfile, 'w+') as outfile:
                    outfile.write(traceback.format_exc())
                ret = render_template('task_complete.html', 
                    log = [x for x in traceback.format_exc().split('\n')],  
                    task_id = uid, 
                    error = e )
                return ret
    
    return render_template('home.html')
Ejemplo n.º 8
0
    def test_convert_configuration(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc3', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            metadata_raw = load_file(
                generate.joinpath('.guides/metadata.json'))
            metadata = json.loads(metadata_raw)

            sections = metadata.get('sections')

            section = sections[0]
            self.assertEqual(section.get('layout'), '2-panels-tree')
            self.assertEqual(len(section.get('files')), 1)
Ejemplo n.º 9
0
    def test_refs_0(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc_ref_0', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_exists = [
                'code/GuessSoln.java', '.guides/book.json',
                '.guides/metadata.json',
                '.guides/content/computer-programming.md',
                '.guides/content/computer-programming-what-is-a-computer-.md',
                '.guides/content/computer-programming-what-is-programming-.md',
                '.guides/content/variables-and-operators.md',
                '.guides/content/variables-and-operators-assigning-variables.md',
                '.guides/content/variables-and-operators-declaring-variables.md'
            ]

            for path in check_exists:
                check = generate.joinpath(path)
                self.assertTrue(check.exists())

            check_content = [
                ('.guides/content/computer-programming.md',
                 'Computer programming content'),
                ('.guides/content/computer-programming-what-is-a-computer-.md',
                 'What is a computer? content'),
                ('.guides/content/computer-programming-what-is-programming-.md',
                 'What is programming? content\n\n0 in section Declaring variables'
                 ),
                ('.guides/content/variables-and-operators.md',
                 'Variables and operators content'),
                ('.guides/content/variables-and-operators-assigning-variables.md',
                 'Assigning variables content\n\n0.1 in section Assigning variables'
                 ),
                ('.guides/content/variables-and-operators-declaring-variables.md',
                 'Declaring variables content')
            ]

            for path, content in check_content:
                file_content = load_file(generate.joinpath(path))
                self.assertEqual(content, file_content)
Ejemplo n.º 10
0
from converter.refs import ref_dict

if __name__ == '__main__':
    parser = ArgumentParser(description='Process latex to codio guides.')
    parser.add_argument('paths',
                        metavar='PATH',
                        type=str,
                        nargs='+',
                        help='path to a book config')
    parser.add_argument('--generate', type=str, help='path to a latex book')
    parser.add_argument('-l', '--log', action='store', default=None)
    parser.add_argument('-y', '--yes', action='store_true')
    parser.add_argument('-r', '--ref', action='store_true')

    args = parser.parse_args()

    logging.basicConfig(filename=args.log,
                        level=logging.DEBUG,
                        format='[%(asctime)s] %(levelname).5s %(message)s',
                        datefmt='%Y.%m.%d %H:%M:%S')

    if args.generate:
        generate_toc(args.paths[0], args.generate)
    elif args.ref:
        config, base_path = load_config_file(args.paths[0])
        ref_dict(config)
    else:
        for path in args.paths:
            config, base_path = load_config_file(path)
            convert(config, base_path, args.yes)
Ejemplo n.º 11
0
    def test_trinket(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc_trinket', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_exists = [
                'code/GuessSoln.java', 'code/Hello.java', 'code/1',
                'code/Hello.java', 'code/GuessSoln.java', '.guides/book.json',
                '.guides/metadata.json',
                '.guides/content/computer-programming.md',
                '.guides/content/computer-programming-what-is-programming-.md',
                '.guides/content/variables-and-operators.md',
                '.guides/content/variables-and-operators-assigning-variables.md',
                '.guides/content/variables-and-operators-declaring-variables.md',
                '.guides/content/computer-programming-what-is-a-computer-.md'
            ]

            for path in check_exists:
                check = generate.joinpath(path)
                self.assertTrue(check.exists(), check)

            check_content = [
                ('.guides/content/computer-programming.md',
                 'Computer programming content'),
                ('.guides/content/computer-programming-what-is-a-computer-.md',
                 """What is a computer? content

```code
public class Hello {

    public static void main(String[] args) {
        // generate some simple output
        System.out.println("Hello, World!");
    }
}
```"""),
                ('.guides/content/computer-programming-what-is-programming-.md',
                 'What is programming? content'),
                ('.guides/content/variables-and-operators.md',
                 """Variables and operators content

```code
public class Hello {

    public static void main(String[] args) {
        // generate some simple output
        System.out.println("Hello, World!");
    }
}
```"""),
                ('.guides/content/variables-and-operators-assigning-variables.md',
                 """Assigning variables content

```code
public class Hello {

    public static void main(String[] args) {
        // generate some simple output
        System.out.println("Hello, World!");
    }
}
```"""),
                ('.guides/content/variables-and-operators-declaring-variables.md',
                 'Declaring variables content')
            ]

            for path, content in check_content:
                file_content = load_file(generate.joinpath(path))
                self.assertEqual(content, file_content)
Ejemplo n.º 12
0
    def test_convert(self):
        with tempfile.TemporaryDirectory() as tmpdir:
            tmp = Path(tmpdir)
            generate = tmp.joinpath('generate')
            config, base_path = load_config_file(
                get_file_path('toc', extension='yml'))
            config['workspace']['directory'] = base_path
            convert(config, tmp, True)

            check_exists = [
                'code/GuessSoln.java', '.guides/book.json',
                '.guides/metadata.json',
                '.guides/content/computer-programming.md',
                '.guides/content/computer-programming-what-is-a-computer-.md',
                '.guides/content/computer-programming-what-is-programming-.md',
                '.guides/content/variables-and-operators.md',
                '.guides/content/variables-and-operators-assigning-variables.md',
                '.guides/content/variables-and-operators-declaring-variables.md'
            ]

            for path in check_exists:
                check = generate.joinpath(path)
                self.assertTrue(check.exists())

            check_content = [
                ('.guides/content/computer-programming.md',
                 'Computer programming content'),
                ('.guides/content/computer-programming-what-is-a-computer-.md',
                 'What is a computer? content'),
                ('.guides/content/computer-programming-what-is-programming-.md',
                 'What is programming? content'),
                ('.guides/content/variables-and-operators.md',
                 'Variables and operators content'),
                ('.guides/content/variables-and-operators-assigning-variables.md',
                 'Assigning variables content'),
                ('.guides/content/variables-and-operators-declaring-variables.md',
                 'Declaring variables content')
            ]

            for path, content in check_content:
                file_content = load_file(generate.joinpath(path))
                self.assertEqual(content, file_content)

            book_raw = load_file(generate.joinpath('.guides/book.json'))
            book = json.loads(book_raw)

            children = book.get('children')
            self.assertEqual(len(children), 2)

            cp = children[0]

            self.assertEqual(cp.get('id'), 'computer-programming')
            self.assertEqual(cp.get('pageId'), 'computer-programming')
            self.assertEqual(cp.get('type'), 'chapter')
            self.assertEqual(cp.get('title'), 'Computer programming')

            cp_children = cp.get('children')

            self.assertEqual(len(cp_children), 2)

            wp = cp_children[1]

            self.assertEqual(wp.get('id'),
                             'computer-programming-what-is-programming-')
            self.assertEqual(wp.get('pageId'),
                             'computer-programming-what-is-programming-')
            self.assertEqual(wp.get('type'), 'page')
            self.assertEqual(wp.get('title'), 'What is programming?')

            metadata_raw = load_file(
                generate.joinpath('.guides/metadata.json'))
            metadata = json.loads(metadata_raw)

            check_sections = {
                'computer-programming': {
                    'content-file': '.guides/content/computer-programming.md',
                    'id': 'computer-programming',
                    'layout': '2-panels',
                    'title': 'Computer programming'
                },
                'computer-programming-what-is-a-computer-': {
                    'content-file':
                    '.guides/content/computer-programming-what-is-a-computer-.md',
                    'id': 'computer-programming-what-is-a-computer-',
                    'title': 'What is a computer?'
                },
                'computer-programming-what-is-programming-': {
                    'content-file':
                    '.guides/content/computer-programming-what-is-programming-.md',
                    'id': 'computer-programming-what-is-programming-',
                    'title': 'What is programming?'
                },
                'variables-and-operators': {
                    'content-file':
                    '.guides/content/variables-and-operators.md',
                    'id': 'variables-and-operators',
                    'title': 'Variables and operators'
                },
                'variables-and-operators-declaring-variables': {
                    'content-file':
                    '.guides/content/variables-and-operators-declaring-variables.md',
                    'id': 'variables-and-operators-declaring-variables',
                    'title': 'Declaring variables'
                },
                'variables-and-operators-assigning-variables': {
                    'content-file':
                    '.guides/content/variables-and-operators-assigning-variables.md',
                    'id': 'variables-and-operators-assigning-variables',
                    'title': 'Assigning variables'
                }
            }

        sections = metadata.get('sections')

        for section in sections:
            verify = check_sections.get(section.get('id'), {})
            self.assertEqual(section.get('id'), verify.get('id'))
            self.assertEqual(section.get('content-file'),
                             verify.get('content-file'))
            self.assertEqual(section.get('title'), verify.get('title'))
            self.assertEqual(section.get('layout'), verify.get('layout'))