常用脚本整理
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
1.6 KiB

#!/usr/bin/python
# -*- coding: UTF-8 -*-
#==================
# Author: Alvis Zhao
# Date: 2020-08-14 11:45:09
# LastEditTime: 2020-08-14 11:51:17
# Description: 下载ubuntu deb软件及其依赖包
#==================
import os
import sys
def showUsage():
print("Usage:")
print(" python download-apt.py net-tools")
def getDepends(pkg):
dependList = []
cmd = 'apt-cache depends ' + pkg + ' | grep Depends |cut -d: -f2 |tr -d "<>" | sort | uniq'
pipeline = os.popen(cmd)
items = pipeline.read().split("\n")
for item in items:
if len(item) > 0:
dependList.append(item)
return dependList
def main():
if len(sys.argv) < 2:
print("用法错误!")
showUsage()
return
pkgAll = []
pkg = sys.argv[1]
outputDir = pkg
pkgAll.append(pkg)
os.popen('mkdir -p ' + outputDir)
# dependList = getDepends(pkg)
# pkgAll = pkgAll + dependList
# 递归深度
depth = 3
count = 0
tempList = []
tempList.append(pkg)
while (count < depth):
count = count + 1
itemDepends = []
for item in tempList:
dependList = getDepends(item)
itemDepends = itemDepends + dependList
pkgAll = pkgAll + itemDepends
tempList = itemDepends
# 先将列表转化为set,再转化为list就可以实现去重操作
pkgAll = list(set(pkgAll))
os.chdir(outputDir)
for item in pkgAll:
# download deb package
print(" downloading " + item)
os.popen('apt-get download ' + item)
if __name__ == '__main__':
main()