Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run lsb_release as command if the Python module is not available #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apt-clone
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from __future__ import print_function

import argparse
import os
import subprocess
import sys

from apt_clone import AptClone
Expand Down Expand Up @@ -132,8 +133,12 @@ if __name__ == "__main__":
# packages because they are probably new defaults pkgs. If however
# we are not yet on the new release its fine to remove installed
# pkgs as part of the upgrade
import lsb_release
codename = lsb_release.get_os_release()["CODENAME"]
try:
import lsb_release
codename = lsb_release.get_os_release()["CODENAME"]
except ImportError:
codename = subprocess.getoutput("lsb_release --codename --short")

if (args.new_distro_codename and args.new_distro_codename == codename):
protect_installed = True
else:
Expand Down
14 changes: 11 additions & 3 deletions apt_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import glob
import hashlib
import logging
import lsb_release
try:
import lsb_release
except ImportError:
lsb_release = None
import os
import re
import shutil
Expand Down Expand Up @@ -71,8 +74,10 @@ def repack_deb(self, pkgname, targetdir):
return (ret == 0)

def debootstrap(self, targetdir, distro=None):
if distro is None:
if distro is None and lsb_release:
distro = lsb_release.get_distro_information()['CODENAME']
if distro is None:
distro = subprocess.getoutput("lsb_release --codename --short")
ret = subprocess.call(["debootstrap", distro, targetdir])
return (ret == 0)

Expand Down Expand Up @@ -187,7 +192,10 @@ def _write_state_installed_pkgs(self, sourcedir, tar):
cache = self._cache_cls(rootdir=sourcedir)
s = ""
foreign = ""
distro_id = lsb_release.get_distro_information()['ID']
if lsb_release:
distro_id = lsb_release.get_distro_information()['ID']
else:
distro_id = subprocess.getoutput("lsb_release --id --short")
for pkg in cache:
if pkg.is_installed:
# a version identifies the pacakge
Expand Down