upgrading packages via script

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

upgrading packages via script

Sebastian P. Luque
Hello,

I'm trying to set up a script to upgrade packages using a cron job,
rather than interactively, as the latter has become a burden.  I'm using
Emacs 25.2.2 from Debian testing, and something is working inherently
different in the script compared to the interactive session.  At any
given time, the interactive session may display a number of packages
that can be upgraded, whereas the script fails to find any, even though
both are run with the same `package-archives' setting.

This is the script I wrote:

╭───── [ upgrade_packages.el ]
│ (setq package-archives
│       (quote
│        (("gnu" . "http://elpa.gnu.org/packages/")
│ ("melpa" . "http://melpa.org/packages/")
│ ("marmalade" . "https://marmalade-repo.org/packages/")
│ ("org" . "http://orgmode.org/elpa/"))))
│ (package-initialize)
│ (list-packages)
│ (package-menu-mark-upgrades)
│ (package-menu-execute t)
╰─────

and this is how I run it:

---<--------------------cut here---------------start------------------->---
$ emacs -q --script upgrade_packages.el
Loading 00debian-vars...
Loading /etc/emacs/site-start.d/20apel.el (source)...
Loading /etc/emacs/site-start.d/50asymptote.el (source)...
Loading /etc/emacs/site-start.d/50auctex.el (source)...
Loading /usr/share/emacs/site-lisp/auctex.el (source)...
Loading /usr/share/emacs/site-lisp/preview-latex.el (source)...
Loading /etc/emacs/site-start.d/50autoconf.el (source)...
Loading /etc/emacs/site-start.d/50bbdb3.el (source)...
Loading /etc/emacs/site-start.d/50cmake-data.el (source)...
Loading /etc/emacs/site-start.d/50devscripts-el.el (source)...
Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
Loading debian-ispell...
Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
Loading /etc/emacs/site-start.d/50dictionary-el.el (source)...
Loading dictionary-init...
Loading /etc/emacs/site-start.d/50dpkg-dev-el.el (source)...
Loading /etc/emacs/site-start.d/50el-get.el (source)...
Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...
Loading /etc/emacs/site-start.d/50festival.el (source)...
Loading /etc/emacs/site-start.d/50flim.el (source)...
Loading /etc/emacs/site-start.d/50gnugo.el (source)...
Loading /etc/emacs/site-start.d/50mailutils-mh.el (source)...
Loading /etc/emacs/site-start.d/50mh-e.el (source)...
Loading /etc/emacs/site-start.d/50mu4e.el (source)...
Loading /etc/emacs/site-start.d/50psvn.el (source)...
Loading /etc/emacs/site-start.d/50pylint.el (source)...
Loading /etc/emacs/site-start.d/50python-docutils.el (source)...
Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...
Loading /etc/emacs/site-start.d/50w3m-el-snapshot.el (source)...
Loading /etc/emacs/site-start.d/51debian-el.el (source)...
Loading /etc/emacs/site-start.d/51semi.el (source)...
Loading /etc/emacs/site-start.d/65wl.el (source)...
Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
Waiting for refresh to finish...
No operations specified
---<--------------------cut here---------------end--------------------->---

Remove the -q option doesn't make a difference.  If I do the same in an
interactive session, there are a number of packages available for
upgrade.  Any idea why the script fails to work?

--
Seb


Reply | Threaded
Open this post in threaded view
|

Re: upgrading packages via script

Michael Heerdegen
Seb <[hidden email]> writes:

> ╭───── [ upgrade_packages.el ]
> │ (setq package-archives
> │       (quote
> │        (("gnu" . "http://elpa.gnu.org/packages/")
> │ ("melpa" . "http://melpa.org/packages/")
> │ ("marmalade" . "https://marmalade-repo.org/packages/")
> │ ("org" . "http://orgmode.org/elpa/"))))
> │ (package-initialize)
> │ (list-packages)
> │ (package-menu-mark-upgrades)
> │ (package-menu-execute t)
> ╰─────

My first guess would be that in nature, one has to wait until the
package manager has refreshed the view before one can select packages to
upgrade.  Your script finishes before that because updating the package
list happens asynchronously.


Michael.

Reply | Threaded
Open this post in threaded view
|

Re: upgrading packages via script

Bastian Beischer-2
In reply to this post by Sebastian P. Luque
Hi Seb,

On Tue, Sep 26, 2017 at 4:55 PM, Seb <[hidden email]> wrote:

>
> Hello,
>
> I'm trying to set up a script to upgrade packages using a cron job,
> rather than interactively, as the latter has become a burden.  I'm using
> Emacs 25.2.2 from Debian testing, and something is working inherently
> different in the script compared to the interactive session.  At any
> given time, the interactive session may display a number of packages
> that can be upgraded, whereas the script fails to find any, even though
> both are run with the same `package-archives' setting.
>
> This is the script I wrote:
>
> ╭───── [ upgrade_packages.el ]
> │ (setq package-archives
> │       (quote
> │        (("gnu" . "http://elpa.gnu.org/packages/")
> │       ("melpa" . "http://melpa.org/packages/")
> │       ("marmalade" . "https://marmalade-repo.org/packages/")
> │       ("org" . "http://orgmode.org/elpa/"))))
> │ (package-initialize)
> │ (list-packages)
> │ (package-menu-mark-upgrades)
> │ (package-menu-execute t)
> ╰─────
>
> and this is how I run it:
>
> ---<--------------------cut here---------------start------------------->---
> $ emacs -q --script upgrade_packages.el
> Loading 00debian-vars...
> Loading /etc/emacs/site-start.d/20apel.el (source)...
> Loading /etc/emacs/site-start.d/50asymptote.el (source)...
> Loading /etc/emacs/site-start.d/50auctex.el (source)...
> Loading /usr/share/emacs/site-lisp/auctex.el (source)...
> Loading /usr/share/emacs/site-lisp/preview-latex.el (source)...
> Loading /etc/emacs/site-start.d/50autoconf.el (source)...
> Loading /etc/emacs/site-start.d/50bbdb3.el (source)...
> Loading /etc/emacs/site-start.d/50cmake-data.el (source)...
> Loading /etc/emacs/site-start.d/50devscripts-el.el (source)...
> Loading /etc/emacs/site-start.d/50dictionaries-common.el (source)...
> Loading debian-ispell...
> Loading /var/cache/dictionaries-common/emacsen-ispell-default.el (source)...
> Loading /var/cache/dictionaries-common/emacsen-ispell-dicts.el (source)...
> Loading /etc/emacs/site-start.d/50dictionary-el.el (source)...
> Loading dictionary-init...
> Loading /etc/emacs/site-start.d/50dpkg-dev-el.el (source)...
> Loading /etc/emacs/site-start.d/50el-get.el (source)...
> Loading /etc/emacs/site-start.d/50emacs-goodies-el.el (source)...
> Loading /etc/emacs/site-start.d/50festival.el (source)...
> Loading /etc/emacs/site-start.d/50flim.el (source)...
> Loading /etc/emacs/site-start.d/50gnugo.el (source)...
> Loading /etc/emacs/site-start.d/50mailutils-mh.el (source)...
> Loading /etc/emacs/site-start.d/50mh-e.el (source)...
> Loading /etc/emacs/site-start.d/50mu4e.el (source)...
> Loading /etc/emacs/site-start.d/50psvn.el (source)...
> Loading /etc/emacs/site-start.d/50pylint.el (source)...
> Loading /etc/emacs/site-start.d/50python-docutils.el (source)...
> Loading /etc/emacs/site-start.d/50texlive-lang-english.el (source)...
> Loading /etc/emacs/site-start.d/50w3m-el-snapshot.el (source)...
> Loading /etc/emacs/site-start.d/51debian-el.el (source)...
> Loading /etc/emacs/site-start.d/51semi.el (source)...
> Loading /etc/emacs/site-start.d/65wl.el (source)...
> Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations
> Waiting for refresh to finish...
> No operations specified
> ---<--------------------cut here---------------end--------------------->---
>
> Remove the -q option doesn't make a difference.  If I do the same in an
> interactive session, there are a number of packages available for
> upgrade.  Any idea why the script fails to work?


You may want to check out the package 'package-utils' which brings the
'package-utils-upgrade-all' function. I'm running this batch script to
do the job:

#!/bin/bash
emacs -q -u $USER -batch -f package-utils-upgrade-all

Cheers
Bastian

>
>
> --
> Seb
>
>

Reply | Threaded
Open this post in threaded view
|

Re: upgrading packages via script

Sebastian P. Luque
On Wed, 27 Sep 2017 16:21:36 +0200,
Bastian Beischer <[hidden email]> wrote:

[...]

> You may want to check out the package 'package-utils' which brings the
> 'package-utils-upgrade-all' function. I'm running this batch script to
> do the job:

> #!/bin/bash emacs -q -u $USER -batch -f package-utils-upgrade-all

> Cheers Bastian

Thanks, I'll give that a try, but I wonder what kind of magic this
package does that a script can't do.  Doesn't "-u $USER" defeat "-q"?

--
Seb


Reply | Threaded
Open this post in threaded view
|

Re: upgrading packages via script

Sebastian P. Luque
In reply to this post by Michael Heerdegen
On Wed, 27 Sep 2017 15:21:26 +0200,
Michael Heerdegen <[hidden email]> wrote:

> Seb <[hidden email]> writes:
>> ╭───── [ upgrade_packages.el ] │ (setq package-archives │ (quote │
>> (("gnu" . "http://elpa.gnu.org/packages/") │ ("melpa"
>> . "http://melpa.org/packages/") │ ("marmalade"
>> . "https://marmalade-repo.org/packages/") │ ("org"
>> . "http://orgmode.org/elpa/")))) │ (package-initialize) │
>> (list-packages) │ (package-menu-mark-upgrades) │
>> (package-menu-execute t) ╰─────

> My first guess would be that in nature, one has to wait until the
> package manager has refreshed the view before one can select packages
> to upgrade.  Your script finishes before that because updating the
> package list happens asynchronously.

That was also my first guess, but in that case shouldn't
(package-menu-execute t) fail altogether?

--
Seb


Reply | Threaded
Open this post in threaded view
|

Re: upgrading packages via script

Sebastian P. Luque
On Wed, 27 Sep 2017 10:33:50 -0500,
Seb <[hidden email]> wrote:

> On Wed, 27 Sep 2017 15:21:26 +0200,
> Michael Heerdegen <[hidden email]> wrote:

>> Seb <[hidden email]> writes:
>>> ╭───── [ upgrade_packages.el ] │ (setq package-archives │ (quote │
>>> (("gnu" . "http://elpa.gnu.org/packages/") │ ("melpa"
>>> . "http://melpa.org/packages/") │ ("marmalade"
>>> . "https://marmalade-repo.org/packages/") │ ("org"
>>> . "http://orgmode.org/elpa/")))) │ (package-initialize) │
>>> (list-packages) │ (package-menu-mark-upgrades) │
>>> (package-menu-execute t) ╰─────

>> My first guess would be that in nature, one has to wait until the
>> package manager has refreshed the view before one can select packages
>> to upgrade.  Your script finishes before that because updating the
>> package list happens asynchronously.

> That was also my first guess, but in that case shouldn't
> (package-menu-execute t) fail altogether?

Well, I found the variable package-menu-async, which if toggled answers
my question.  If set to nil in the script, then packages to upgrade are
found successfully against the latest candidates.  If non-nil, as by
default, then things go wrong as shown, so answer is no.

And the working script boils down to:

╭───── [ upgrade_packages.el ]
│ (setq package-archives
│       (quote
│        (("gnu" . "http://elpa.gnu.org/packages/")
│ ("melpa" . "http://melpa.org/packages/")
│ ("marmalade" . "https://marmalade-repo.org/packages/")
│ ("org" . "http://orgmode.org/elpa/")))
│       package-menu-async nil)
│ (list-packages)
│ (package-menu-mark-upgrades)
│ (package-menu-execute t)
╰─────

--
Seb