Last active
March 10, 2018 19:23
-
-
Save Zirak/5eb7db795533a2c27327 to your computer and use it in GitHub Desktop.
Mirror Elpa (or Melpa or whatever)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;; | |
;; https://github.com/Zirak/mirror-elpa | |
;;;;;;;;;; | |
;; mirrors melpa into a ~packages~ subdirectory | |
;; you can run a web-server in said subdirectory and use it as a package archive | |
(defun read-archive (url) | |
(with-temp-file (expand-file-name "archive-contents" "packages") | |
(url-insert-file-contents (concat url "archive-contents")) | |
(cdr (read (current-buffer))))) | |
(defun save-archive (base-url archive-name) | |
(message (concat "Downloading " archive-name)) | |
(let ((file-name (expand-file-name archive-name "packages"))) | |
(if (file-exists-p file-name) | |
(message (concat "Already have" archive-name)) | |
(url-copy-file (concat base-url archive-name) file-name)))) | |
(defun get-full-package-name (package) | |
;; name-version.extension | |
(concat | |
(get-package-name package) | |
"-" | |
(get-package-version-string package) | |
"." | |
(get-package-extension package))) | |
(defun get-package-name (package) | |
;; (package-name ...) | |
(symbol-name (car package))) | |
(defun get-package-version-string (package) | |
;; (package-name [(date version) ...])" | |
(let ((version-tuple (elt (cdr package) 0))) | |
(concat | |
(number-to-string (car version-tuple)) | |
"." | |
(number-to-string (elt version-tuple 1))))) | |
(defun get-package-extension (package) | |
;; (package-name . [(date version) something docstring package-type])" | |
(let ((package-type (elt (cdr package) 3))) | |
(cond ((eq package-type 'single) "el") | |
((eq package-type 'tar) "tar")))) | |
;; static void main | |
(setq melpa-url "http://melpa.org/packages/") | |
(unless (file-exists-p "packages") | |
(make-directory "packages")) | |
(dolist (package (read-archive melpa-url)) | |
(save-archive melpa-url (get-full-package-name package))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
marmalade repo contains version tuples of length 1, line 36 needs to be replaced with: