mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-24 04:11:41 +00:00
Ignore the footprints_custom.txt and symbols_custom.txt in git and create them on the fly if needed
Otherwise it breaks the update mechanism
This commit is contained in:
parent
955e622c1a
commit
abb1581c0f
4 changed files with 47 additions and 3 deletions
3
public/kicad/.gitignore
vendored
Normal file
3
public/kicad/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# They are user generated and should not be tracked by git
|
||||||
|
footprints_custom.txt
|
||||||
|
symbols_custom.txt
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
# Custom KiCad autocomplete entries. One entry per line.
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
# Custom KiCad autocomplete entries. One entry per line.
|
|
||||||
|
|
@ -24,14 +24,20 @@ namespace App\Services\EDA;
|
||||||
|
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||||
|
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
|
||||||
|
|
||||||
final class KicadListFileManager
|
final class KicadListFileManager implements CacheWarmerInterface
|
||||||
{
|
{
|
||||||
private const FOOTPRINTS_PATH = '/public/kicad/footprints.txt';
|
private const FOOTPRINTS_PATH = '/public/kicad/footprints.txt';
|
||||||
private const SYMBOLS_PATH = '/public/kicad/symbols.txt';
|
private const SYMBOLS_PATH = '/public/kicad/symbols.txt';
|
||||||
private const CUSTOM_FOOTPRINTS_PATH = '/public/kicad/footprints_custom.txt';
|
private const CUSTOM_FOOTPRINTS_PATH = '/public/kicad/footprints_custom.txt';
|
||||||
private const CUSTOM_SYMBOLS_PATH = '/public/kicad/symbols_custom.txt';
|
private const CUSTOM_SYMBOLS_PATH = '/public/kicad/symbols_custom.txt';
|
||||||
|
|
||||||
|
private const CUSTOM_TEMPLATE = <<<'EOT'
|
||||||
|
# Custom KiCad autocomplete entries. One entry per line.
|
||||||
|
|
||||||
|
EOT;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
#[Autowire('%kernel.project_dir%')]
|
#[Autowire('%kernel.project_dir%')]
|
||||||
private readonly string $projectDir,
|
private readonly string $projectDir,
|
||||||
|
|
@ -45,6 +51,8 @@ final class KicadListFileManager
|
||||||
|
|
||||||
public function getCustomFootprintsContent(): string
|
public function getCustomFootprintsContent(): string
|
||||||
{
|
{
|
||||||
|
//Ensure that the custom file exists, so that the UI can always display it without error.
|
||||||
|
$this->createCustomFileIfNotExists(self::CUSTOM_FOOTPRINTS_PATH);
|
||||||
return $this->readFile(self::CUSTOM_FOOTPRINTS_PATH);
|
return $this->readFile(self::CUSTOM_FOOTPRINTS_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,6 +63,8 @@ final class KicadListFileManager
|
||||||
|
|
||||||
public function getCustomSymbolsContent(): string
|
public function getCustomSymbolsContent(): string
|
||||||
{
|
{
|
||||||
|
//Ensure that the custom file exists, so that the UI can always display it without error.
|
||||||
|
$this->createCustomFileIfNotExists(self::CUSTOM_SYMBOLS_PATH);
|
||||||
return $this->readFile(self::CUSTOM_SYMBOLS_PATH);
|
return $this->readFile(self::CUSTOM_SYMBOLS_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,4 +115,37 @@ final class KicadListFileManager
|
||||||
|
|
||||||
return $normalized;
|
return $normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createCustomFileIfNotExists(string $path): void
|
||||||
|
{
|
||||||
|
$fullPath = $this->projectDir . $path;
|
||||||
|
|
||||||
|
if (!is_file($fullPath)) {
|
||||||
|
if (file_put_contents($fullPath, self::CUSTOM_TEMPLATE, LOCK_EX) === false) {
|
||||||
|
throw new RuntimeException(sprintf('Failed to create custom footprints file "%s".', $fullPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the custom footprints and symbols files exist, so that the UI can always display them without error.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function createCustomFilesIfNotExist(): void
|
||||||
|
{
|
||||||
|
$this->createCustomFileIfNotExists(self::CUSTOM_FOOTPRINTS_PATH);
|
||||||
|
$this->createCustomFileIfNotExists(self::CUSTOM_SYMBOLS_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function isOptional(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function warmUp(string $cacheDir, ?string $buildDir = null): array
|
||||||
|
{
|
||||||
|
$this->createCustomFilesIfNotExist();
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue