deepin add-apt-repository 诸多问题及其解决

deepin不会自带这个命令的,需要安装

apt-get install python-software-properties
sudo apt-get install software-properties-common

知乎上的解决方法:
https://www.zhihu.com/question/30361833/answer/84878458

测试命令:

sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php

但是使用起来会报错:

Traceback (most recent call last):
  File "/usr/bin/add-apt-repository", line 160, in <module>
    sp = SoftwareProperties(options=options)
  File "/usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.py", line 96, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.py", line 584, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)    
  File "/usr/lib/python2.7/dist-packages/aptsources/distro.py", line 93, in get_sources
    (self.id, self.codename))
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Deepin/stable

我们看到/usr/share/python-apt/templates/Deepin.info

Suite: unstable
RepositoryType: deb
BaseURI: http://packages.deepin.com/deepin/
MatchURI: \.deepin\.com
MirrorsFile: Deepin.mirrors
Description: Deepin 'unstable'
Component: main
CompDescription: Officially supported
Component: contrib
CompDescription: DFSG-compatible Software with Non-Free Dependencies
Component: non-free
CompDescription: Non-DFSG-compatible Software

(没什么卵用)

修改/etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=wily
DISTRIB-DESCRIPTION="Ubuntu wily"

最后需要修改一下/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py文件

#  software-properties backend
#
#  Copyright (c) 2004-2007 Canonical Ltd.
#                2004-2005 Michiel Sikkes
#
#  Author: Michiel Sikkes <michiel@eyesopened.nl>
#          Michael Vogt <mvo@debian.org>
#          Sebastian Heinlein <glatzor@ubuntu.com>
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
#  USA

from __future__ import absolute_import, print_function

import apt_pkg
import copy
from hashlib import md5
import re
import os
import glob
import shutil
import threading
import atexit
import tempfile
try:
  from string import maketrans
except ImportError:
  maketrans = str.maketrans
import stat

from tempfile import NamedTemporaryFile
from xml.sax.saxutils import escape
try:
  from configparser import ConfigParser
except ImportError:
  from ConfigParser import ConfigParser
from gettext import gettext as _

import aptsources
import aptsources.distro
import softwareproperties

from .AptAuth import AptAuth
from aptsources.sourceslist import SourcesList, SourceEntry
from . import shortcuts
from . import ppa
from . import cloudarchive

_SHORTCUT_FACTORIES = [
    ppa.shortcut_handler,
    cloudarchive.shortcut_handler,
    shortcuts.shortcut_handler,
]


class SoftwareProperties(object):

  # known (whitelisted) channels
  CHANNEL_PATH="/usr/share/app-install/channels/"

  # release upgrades policy
  RELEASE_UPGRADES_CONF = "/etc/update-manager/release-upgrades"
  #RELEASE_UPGRADES_CONF = "/tmp/release-upgrades"
  (
    RELEASE_UPGRADES_NORMAL,
    RELEASE_UPGRADES_LTS,
    RELEASE_UPGRADES_NEVER
  ) = list(range(3))
  release_upgrades_policy_map = {
   
    RELEASE_UPGRADES_NORMAL : 'normal',
    RELEASE_UPGRADES_LTS    : 'lts',
    RELEASE_UPGRADES_NEVER  : 'never',
  }
  
  def __init__(self, datadir=None, options=None, rootdir="/"):
    """ Provides the core functionality to configure the used software 
        repositories, the corresponding authentication keys and 
        update automation """
    self.popconfile = rootdir+"/etc/popularity-contest.conf"

    self.rootdir = rootdir
    if rootdir != "/":
      apt_pkg.config.set("Dir", rootdir)

    # FIXME: some saner way is needed here
    if datadir == None:
      datadir = "/usr/share/software-properties/"
    self.options = options
    self.datadir = datadir

    self.sourceslist = SourcesList()
    self.distro = aptsources.distro.get_distro()
    
    self.seen_server = []
    self.modified_sourceslist = False

    self.reload_sourceslist()
    self.backup_sourceslist()

    self.backup_apt_conf()

    # FIXME: we need to store this value in a config option
    #self.custom_mirrors = ["http://adasdwww.de/ubuntu"]
    self.custom_mirrors= []

    # apt-key stuff
    self.apt_key = AptAuth(rootdir=rootdir)

    atexit.register(self.wait_for_threads)

  def wait_for_threads(self):
    " wait for all running threads (PPA key fetchers) to exit "
    for t in threading.enumerate():
      if t.ident != threading.current_thread().ident:
        t.join()

  def backup_apt_conf(self):
    """Backup all apt configuration options"""
    self.apt_conf_backup = {
   }
    for option in softwareproperties.CONF_MAP.keys():
        value = apt_pkg.config.find_i(softwareproperties.CONF_MAP[option])
        self.apt_conf_backup[option] = value

  def restore_apt_conf(self):
    """Restore the stored apt configuration"""
    for option in self.apt_conf_backup.keys():
        apt_pkg.config.set(softwareproperties.CONF_MAP[option],
                           str(self.apt_conf_backup[option]))
    self.write_config()

  def get_update_automation_level(self):
    """ Parse the apt cron configuration. Try to fit a predefined use case 
        and return it. Special case: if the user made a custom 
        configurtation, that we cannot represent it will return None """
    if apt_pkg.config.find_i(softwareproperties.CONF_MAP["autoupdate"]) > 0:
        # Autodownload
        if apt_pkg.config.find_i(softwareproperties.CONF_MAP["unattended"]) == 1\
           and os.path.exists("/usr/bin/unattended-upgrade"):
            return softwareproperties.UPDATE_INST_SEC
        elif apt_pkg.config.find_i(softwareproperties.CONF_MAP["autodownload"]) == 1 and  \
             apt_pkg.config.find_i(softwareproperties.CONF_MAP["unattended"]) == 0:
            return softwareproperties.UPDATE_DOWNLOAD
        elif apt_pkg.config.find_i(softwareproperties.CONF_MAP["unattended"]) == 0 and \
             apt_pkg.config.find_i(softwareproperties.CONF_MAP["autodownload"]) == 0:
            return softwareproperties.UPDATE_NOTIFY
        else:
            return None
    elif apt_pkg.config.find_i(softwareproperties.CONF_MAP["unattended"]) == 0 and \
         apt_pkg.config.find_i(softwareproperties.CONF_MAP["autodownload"]) == 0:
        return softwareproperties.UPDATE_MANUAL
    else:
        return None

  def set_update_automation_level(self, state):
    """ Set the apt periodic configurtation to the selected 
        update automation level. To synchronize the cache update and the 
        actual upgrading function, the upgrade function, e.g. unattended, 
        will run every day, if enabled. """
    if state == softwareproperties.UPDATE_INST_SEC:
        apt_pkg.config.set(softwareproperties.CONF_MAP["unattended"], str(1))
        apt_pkg.config.set(softwareproperties.CONF_MAP["autodownload"], str(1))
    elif state == softwareproperties.UPDATE_DOWNLOAD:
        apt_pkg.config.set(softwareproperties.CONF_MAP["autodownload"], str(1))
        apt_pkg.config.set(softwareproperties.CONF_MAP["unattended"], str(0))
    elif s
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值