Пример #1
0
    def save_as_project(self):
        project = attr.evolve(self.project)
        project.filename = None
        # TODO: this is still going to mutate the same object as the
        #       original project is referencing
        project.paths.set_all(None)

        project.save(parent=self.main_window)
        self.project = project
Пример #2
0
Файл: main.py Проект: epcmatt/pm
def transition(target_path):
    """Don't use this unless you know"""
    target_path = pathlib.Path(target_path)

    click.echo('Working in: {}'.format(target_path))
    value = click.prompt(
        'This will wipe out changes in the above project path, continue? ',
        prompt_suffix='',
    )

    if value != 'yep':
        click.echo('Sorry, that response is not acceptable to continue.')
        return

    c_project = target_path / '.cproject'

    library_path = target_path / 'embedded-library'

    original_spreadsheet = library_path / 'MODBUS_SunSpec-EPC.xls'
    new_spreadsheet = original_spreadsheet.with_suffix('.xlsx')

    tables_py = library_path / 'python' / 'embeddedlibrary' / 'tables.py'
    sunspecparser_py = (library_path / 'python' / 'embeddedlibrary' /
                        'sunspecparser.py')

    subprocess.run(['git', 'reset', '.'], check=True, cwd=library_path)
    subprocess.run(['git', 'checkout', '--', '.'],
                   check=True,
                   cwd=library_path)
    subprocess.run(['git', 'clean', '-fdx'], check=True, cwd=library_path)
    subprocess.run(
        [
            'libreoffice', '--convert-to', 'xlsx', '--outdir',
            os.fspath(library_path),
            os.fspath(original_spreadsheet)
        ],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ['git', 'rm', os.fspath(tables_py)],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ['git', 'rm', os.fspath(original_spreadsheet)],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ['git', 'add', os.fspath(new_spreadsheet)],
        check=True,
        cwd=library_path,
    )

    subprocess.run(['git', 'reset', '.'], check=True, cwd=target_path)
    subprocess.run(['git', 'checkout', '--', '.'], check=True, cwd=target_path)
    subprocess.run(
        ['git', 'clean', '-fdx', '--exclude', 'venv'],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        ['python',
         os.fspath(target_path / 'create_venv.py'), 'ensure'],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        [
            target_path / 'venv' / 'bin' / 'sunspecparser',
            os.fspath(new_spreadsheet)
        ],
        check=True,
        cwd=library_path,  # it expects to be in _some_ subdirectory and then ..
    )
    subprocess.run(
        ['sed', '-i', r's/\.xls/\.xlsx/g',
         os.fspath(c_project)],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        ['git', 'add', os.fspath(c_project)],
        check=True,
        cwd=target_path,
    )

    content = sunspecparser_py.read_text()
    with sunspecparser_py.open('w', newline='\n') as f:
        for line in content.splitlines():
            f.write(line + '\n')
            if r"""'#include "faultHandler.h"\n'""" in line:
                f.write(
                    r"""            c_file.write('#include "sunspecInterface{:>05}.h"\n'.format(model))"""
                    '\n')
                f.write(r"""            c_file.write('#include "math.h"\n')"""
                        '\n')

    subprocess.run(
        ['git', 'add', os.fspath(sunspecparser_py)],
        check=True,
        cwd=library_path,
    )

    paths = epcpm.importexportdialog.paths_from_directory(target_path)
    print(paths)

    project = epcpm.importexport.full_import(paths=paths, )

    pm_directory = target_path / 'interface' / 'pm'
    pm_directory.mkdir(exist_ok=True)
    project.filename = pm_directory / 'project.pmp'
    project.save()

    subprocess.run(
        ['git', 'add', os.fspath(pm_directory)],
        check=True,
        cwd=target_path,
    )

    epcpm.importexport.full_export(
        project=project,
        paths=paths,
        first_time=True,
    )

    click.echo()
    click.echo('done')
Пример #3
0
def transition(target_path):
    """Don't use this unless you know"""
    target_path = pathlib.Path(target_path)

    click.echo("Working in: {}".format(target_path))
    value = click.prompt(
        "This will wipe out changes in the above project path, continue? ",
        prompt_suffix="",
    )

    if value != "yep":
        click.echo("Sorry, that response is not acceptable to continue.")
        return

    c_project = target_path / ".cproject"

    library_path = target_path / "embedded-library"

    original_spreadsheet = library_path / "MODBUS_SunSpec-EPC.xls"
    new_spreadsheet = original_spreadsheet.with_suffix(".xlsx")

    tables_py = library_path / "python" / "embeddedlibrary" / "tables.py"
    sunspecparser_py = library_path / "python" / "embeddedlibrary" / "sunspecparser.py"

    subprocess.run(["git", "reset", "."], check=True, cwd=library_path)
    subprocess.run(["git", "checkout", "--", "."],
                   check=True,
                   cwd=library_path)
    subprocess.run(["git", "clean", "-fdx"], check=True, cwd=library_path)
    subprocess.run(
        [
            "libreoffice",
            "--convert-to",
            "xlsx",
            "--outdir",
            os.fspath(library_path),
            os.fspath(original_spreadsheet),
        ],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ["git", "rm", os.fspath(tables_py)],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ["git", "rm", os.fspath(original_spreadsheet)],
        check=True,
        cwd=library_path,
    )
    subprocess.run(
        ["git", "add", os.fspath(new_spreadsheet)],
        check=True,
        cwd=library_path,
    )

    subprocess.run(["git", "reset", "."], check=True, cwd=target_path)
    subprocess.run(["git", "checkout", "--", "."], check=True, cwd=target_path)
    subprocess.run(
        ["git", "clean", "-fdx", "--exclude", "venv"],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        ["python",
         os.fspath(target_path / "create_venv.py"), "ensure"],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        [
            target_path / "venv" / "bin" / "sunspecparser",
            os.fspath(new_spreadsheet)
        ],
        check=True,
        cwd=library_path,  # it expects to be in _some_ subdirectory and then ..
    )
    subprocess.run(
        ["sed", "-i", r"s/\.xls/\.xlsx/g",
         os.fspath(c_project)],
        check=True,
        cwd=target_path,
    )
    subprocess.run(
        ["git", "add", os.fspath(c_project)],
        check=True,
        cwd=target_path,
    )

    content = sunspecparser_py.read_text()
    with sunspecparser_py.open("w", newline="\n") as f:
        for line in content.splitlines():
            f.write(line + "\n")
            if r"""'#include "faultHandler.h"\n'""" in line:
                f.write(
                    r"""            c_file.write('#include "sunspecInterface{:>05}.h"\n'.format(model))"""
                    "\n")
                f.write(r"""            c_file.write('#include "math.h"\n')"""
                        "\n")

    subprocess.run(
        ["git", "add", os.fspath(sunspecparser_py)],
        check=True,
        cwd=library_path,
    )

    paths = epcpm.importexportdialog.paths_from_directory(target_path)
    print(paths)

    project = epcpm.importexport.full_import(paths=paths, )

    pm_directory = target_path / "interface" / "pm"
    pm_directory.mkdir(exist_ok=True)
    project.filename = pm_directory / "project.pmp"
    project.save()

    subprocess.run(
        ["git", "add", os.fspath(pm_directory)],
        check=True,
        cwd=target_path,
    )

    epcpm.importexport.full_export(
        project=project,
        paths=paths,
        first_time=True,
    )

    click.echo()
    click.echo("done")
Пример #4
0
def test_x():
    project = epcpm.project.loadp(here/'project'/'project.pmp')

    attrs_model = project.models.sunspec
    parameter_model = project.models.parameters

    enumerations = parameter_model.list_selection_roots['enumerations']
    sunspec_types = epcpm.sunspecmodel.build_sunspec_types_enumeration()
    enumerations.append_child(sunspec_types)
    parameter_model.list_selection_roots['sunspec types'] = sunspec_types

    requested_models = [1, 17, 103, 65534]
    sunspec_models = epcpm.smdxtosunspec.import_models(
        *requested_models,
        parameter_model=parameter_model,
        paths=[smdx_path],
    )

    for sunspec_model in sunspec_models:
        attrs_model.root.append_child(sunspec_model)

    points = (
        (model, block, point)
        for model in attrs_model.root.children
        if isinstance(model, epcpm.sunspecmodel.Model)
        for block in model.children
        for point in block.children
    )

    get_set = epcpm.smdxtosunspec.import_get_set(
        smdx_path/'MODBUS_SunSpec-EPC.xlsx',
    )

    for model, block, point in points:
        parameter = attrs_model.node_from_uuid(point.parameter_uuid)
        for direction in ('get', 'set'):
            key = epcpm.smdxtosunspec.GetSetKey(
                model=model.id,
                name=parameter.abbreviation,
                get_set=direction,
            )
            accessor = get_set.get(key)
            if accessor is not None:
                setattr(point, direction, accessor)

    project.filename = here/'project_with_sunspec'/'project.pmp'
    project.paths['sunspec'] = 'sunspec.json'
    project.filename.parent.mkdir(parents=True, exist_ok=True)
    project.save()

    builder = epcpm.sunspectoxlsx.builders.wrap(
        wrapped=attrs_model.root,
        parameter_uuid_finder=attrs_model.node_from_uuid,
        parameter_model=project.models.parameters,
        column_filter=epcpm.sunspectoxlsx.attr_fill(
            epcpm.sunspectoxlsx.Fields,
            True
        ),
    )

    workbook = builder.gen()

    assert workbook.sheetnames == [
        'License Agreement',
        'Summary',
        'Index',
        '1',
        '17',
        '103',
        '65534',
    ]

    workbook.save('test_sunspectoxlsx.xlsx')

    with open('test_sunspectoxlsx.csv', 'w', newline='') as file:
        writer = csv.writer(file)

        for sheet in workbook.worksheets:
            for row in sheet.rows:
                writer.writerow(cell.value for cell in row)