Skip to content

Commit

Permalink
Added support for partially saved projects (KiCad 6).
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Jun 7, 2022
1 parent fc77797 commit 7c5d337
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Support for partially saved projects (KiCad 6). (See INTI-CMNB/kicad_auto#11)

## [1.6.13] - 2022-06-06
### Added
Expand Down
29 changes: 26 additions & 3 deletions kiauto/file_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 Salvador E. Tropea
# Copyright (c) 2020-2021 Instituto Nacional de Tecnologïa Industrial
# Copyright (c) 2020-2022 Salvador E. Tropea
# Copyright (c) 2020-2022 Instituto Nacional de Tecnologïa Industrial
# Copyright (c) 2019 Jesse Vincent (@obra)
# Copyright (c) 2018-2019 Seppe Stas (@seppestas) (Productize SPRL)
# Based on ideas by: Scott Bezek (@scottbez1)
Expand All @@ -22,7 +22,7 @@
import psutil
import json

from kiauto.misc import (WRONG_ARGUMENTS, KICAD_VERSION_5_99, Config)
from kiauto.misc import (WRONG_ARGUMENTS, KICAD_VERSION_5_99, Config, READ_ONLY_PROBLEM)
from kiauto import log
logger = log.get_logger(__name__)
time_out_scale = 1.0
Expand Down Expand Up @@ -258,6 +258,14 @@ def create_kicad_config(cfg):
text_file.write(key.upper()+'='+vars[key]+'\n')


def restore_autosave(name):
""" Restores de auto save information """
old_name = name[:-11]
if os.path.isfile(name):
logger.debug('Restoring {} -> {}'.format(name, old_name))
os.rename(name, old_name)


def check_input_file(cfg, no_file, no_ext):
# Check the schematic/PCB is there
if not os.path.isfile(cfg.input_file):
Expand All @@ -271,6 +279,21 @@ def check_input_file(cfg, no_file, no_ext):
exit(no_ext)
if cfg.kicad_version >= KICAD_VERSION_5_99 and ext == '.sch':
logger.warning('Using old format files is not recommended. Convert them first.')
# KiCad 6 uses #auto_saved_files# to store autosave info
fauto = os.path.join(os.path.dirname(cfg.input_file), '#auto_saved_files#')
if os.path.isfile(fauto):
logger.warning('Partially saved project detected, please double check it')
# Rename it so KiCad doesn't ask about restoring autosaved files
fauto_new = fauto+'.moved_away'
logger.debug('Renaming {} -> {}'.format(fauto, fauto_new))
try:
os.rename(fauto, fauto_new)
except PermissionError:
# Read-only directory or file system, give up
logger.error('Unable to rename `{}` please remove it manually'.format(fauto))
exit(READ_ONLY_PROBLEM)
# Restore it at exit
atexit.register(restore_autosave, fauto_new)


def memorize_project(cfg):
Expand Down
1 change: 1 addition & 0 deletions kiauto/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
NO_EN_LOCALE = 14
MISSING_TOOL = 15
KICAD_DIED = 16
READ_ONLY_PROBLEM = 17
# Wait 60 s to pcbnew/eeschema window to be present
WAIT_START = 60
# Name for testing versions
Expand Down
4 changes: 2 additions & 2 deletions src/eeschema_do
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 Salvador E. Tropea
# Copyright (c) 2020-2021 Instituto Nacional de Tecnologïa Industrial
# Copyright (c) 2020-2022 Salvador E. Tropea
# Copyright (c) 2020-2022 Instituto Nacional de Tecnologïa Industrial
# Copyright (c) 2019 Jesse Vincent (@obra)
# Copyright (c) 2018-2019 Seppe Stas (@seppestas) (Productize SPRL)
# Based on ideas by: Scott Bezek (@scottbez1)
Expand Down
2 changes: 2 additions & 0 deletions tests/kicad6/good-project/#auto_saved_files#
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
C:\code\KiCad\EduboardV2_Baseboard\_autosave-power.kicad_sch
C:\code\KiCad\EduboardV2_Baseboard\_autosave-connectors.kicad_sch

0 comments on commit 7c5d337

Please sign in to comment.