executable_src-import.scm 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/run/current-system/profile/bin/guile \
  2. --no-auto-compile -e (src-import) -s
  3. !#
  4. (define-module (src-import)
  5. #:use-module (ice-9 ftw)
  6. #:use-module (srfi srfi-1)
  7. #:use-module (ice-9 match)
  8. #:use-module (ice-9 format)
  9. #:use-module (ice-9 string-fun)
  10. #:use-module (srfi srfi-26)
  11. #:use-module (guix records)
  12. #:use-module (ice-9 pretty-print)
  13. #:export (main))
  14. (define (project-directories basedir)
  15. "Return a list of Git projects excluding worktrees in BASEDIR."
  16. (let ((scandir-predicate (lambda (file)
  17. (and (not (string= file "."))
  18. (not (string= file ".."))))))
  19. (sort (filter
  20. (lambda (project-directory)
  21. (and (match (scandir project-directory
  22. (lambda (file)
  23. (string= file ".git")))
  24. ((".git") #t)
  25. (_ #f))
  26. (match (scandir (string-append project-directory "/.git")
  27. (lambda (file)
  28. (string= file "config")))
  29. (("config") #t)
  30. (_ #f))))
  31. (apply append
  32. (fold (lambda (group groups)
  33. (let ((group-directory (string-append basedir "/" group)))
  34. (cons (map (lambda (project)
  35. (string-append group-directory "/" project))
  36. (scandir group-directory scandir-predicate))
  37. groups)))
  38. '()
  39. (scandir basedir scandir-predicate))))
  40. string<)))
  41. (define %basedir
  42. (and=> (getenv "HOME")
  43. (lambda (home)
  44. (string-append home "/majordomo"))))
  45. (define (main args)
  46. (define projects
  47. (project-directories %basedir))
  48. (for-each (lambda (project)
  49. (pretty-print project #:width 10)
  50. (newline))
  51. (map (lambda (project)
  52. (match (string-split (string-replace-substring
  53. project (string-append %basedir "/") "")
  54. #\/)
  55. ((group name)
  56. (let ((group (match group
  57. ("_ci" "ci")
  58. (group group))))
  59. `(define-public ,(string->symbol
  60. (string-append "git-project-" group "-" name))
  61. (git-project
  62. (name ,name)
  63. (group ,group)
  64. (output ,project)))))))
  65. projects)))