export_jlcpcb.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. # Copyright 2021 Scott Bezek and the splitflap contributors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import argparse
  16. import logging
  17. import os
  18. import subprocess
  19. import sys
  20. electronics_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  21. repo_root = os.path.dirname(electronics_root)
  22. sys.path.append(repo_root)
  23. from util import file_util
  24. from export_util import (
  25. versioned_file,
  26. )
  27. logging.basicConfig(level=logging.DEBUG)
  28. logger = logging.getLogger(__name__)
  29. def export_jlcpcb(pcb, schematic, alt_fields):
  30. pcb_file = os.path.abspath(pcb)
  31. output_dir = os.path.join(electronics_root, 'build', os.path.splitext(os.path.basename(pcb_file))[0] + '-jlc')
  32. file_util.mkdir_p(output_dir)
  33. with versioned_file(pcb_file):
  34. command = [
  35. 'kikit',
  36. 'fab',
  37. 'jlcpcb',
  38. ]
  39. if schematic is not None:
  40. schematic_file = os.path.abspath(schematic)
  41. command += [
  42. '--assembly',
  43. '--schematic',
  44. schematic_file,
  45. '--field',
  46. ]
  47. command.append(','.join(alt_fields + ['LCSC']))
  48. command += [
  49. pcb_file,
  50. output_dir,
  51. ]
  52. subprocess.check_call(command)
  53. if __name__ == '__main__':
  54. parser = argparse.ArgumentParser()
  55. parser.add_argument('pcb')
  56. parser.add_argument('--assembly-schematic')
  57. parser.add_argument('--alt-fields', nargs='+')
  58. args = parser.parse_args()
  59. export_jlcpcb(args.pcb, args.assembly_schematic, args.alt_fields)