在python 3.6中合并具有不同参数的两个函数

时间:2018-10-23 00:49:54

标签: python python-3.6

我该如何仅针对以下代码中缺少的补丁程序调用apply_patches()函数?

代码检查补丁= [27923320、27547329、21171382、21463894、18961555、28432129],然后调用函数apply_patches来应用missing_patches。不幸的是,补丁27923320、27547329解压缩到目录/ u02 / 28317232 /中,而其他补丁解压缩到/ u02 /

/ u02 /

的内容
[oracle@cdb1 u02]$ pwd
/u02
[oracle@cdb1 u02]$ ls -ltr
total 789832
drwxrwxr-x.  4 oracle oinstall      4096 Aug  6  2015 21463894
drwxrwxr-x.  4 oracle oinstall      4096 Apr 25 15:18 18961555
drwxrwxr-x.  4 oracle oinstall      4096 Jun 27 10:48 21171382
drwxrwxr-x.  4 oracle oinstall      4096 Aug  7 18:32 28432129
-rw-rw-r--.  1 oracle oinstall      4596 Aug  8 07:01 PatchSearch.xml
-rwxrwx---.  1 oracle oinstall     30301 Oct 17 20:59 p18961555_12102180417_Linux-x86-64.zip
-rwxrwx---.  1 oracle oinstall    212238 Oct 17 21:00 p28432129_12102180717_Linux-x86-64.zip
-rwxrwx---.  1 oracle oinstall 807969208 Oct 17 21:01 p28317232_121020_Linux-x86-64.zip
-rwxrwx---.  1 oracle oinstall    451814 Oct 17 21:01 p21171382_12102180417_Generic.zip
-rwxrwx---.  1 oracle oinstall     73502 Oct 17 21:10 p21463894_121020_Linux-x86-64.zip
drwxr-xr-x. 10 oracle oinstall      4096 Oct 18 08:52 pycharm-community-2018.2.4
drwxr-xr-x.  3 oracle oinstall      4096 Oct 18 09:23 scripts
drwxr-xr-x.  4 oracle oinstall      4096 Oct 21 09:11 28317232
[oracle@cdb1 u02]$ 

[oracle@cdb1 u02]$ cd 28317232
[oracle@cdb1 28317232]$ pwd
/u02/28317232
[oracle@cdb1 28317232]$ ls -ltr
total 40
-rw-r--r--.  1 oracle oinstall    21 Jul 10 18:59 README.txt
-rw-rw-r--.  1 oracle oinstall 24710 Jul 12 07:27 README.html
drwxr-xr-x. 18 oracle oinstall  4096 Oct 21 09:11 27547329
drwxr-xr-x.  4 oracle oinstall  4096 Oct 21 09:11 27923320

代码:

!/usr/local/bin/python3.6
    import re
    import subprocess
    from plumbum import local, cmd


    osTyp = cmd.uname('-s').strip()

    def apply_patches(msg, patch, zipfile, dir):
        print(msg)
        for j in patch:
            if osTyp == 'Linux':
                local.cwd.chdir('/u02/')
                cmd.unzip('-o', zipfile.format(j))
                local.cwd.chdir(dir.format(j))
                cmd.opatch('apply', '-silent')
                print('Patch' ,j, 'applied')
            elif osTyp == 'SunOs':
                cmd.unzip("p{}_121020_Solaris-x86-64.zip".format(j))
            else:
                print("!!\n!! unable to determine OS type !!\n!!")



    s = subprocess.check_output(["opatch", "lsinventory"])
    output = s.decode("utf-8")


    patches = [27923320, 27547329, 21171382, 21463894, 18961555, 28432129]

    patches_found = set(re.findall(r'\b(?:%s)\b' % '|'.join(map(str, patches)), output))
    patches_missing = set(map(str, patches)) - patches_found

    if patches_found:
        print('Patch', patches_found, "detected")

    if patches_missing:
        print("Patch", patches_missing, "missing")

    if ("27923320", "27547329" in patches_missing):
        apply_patches('Applying PSU patches', [27923320, 27547329], "/u02/p28317232*.zip", "/u02/28317232/{}")
    else:
         apply_patches('Applying one-off patches', [21171382, 21463894, 18961555, 28432129], "/u02/p{}_*.zip", "/u02/{}")

0 个答案:

没有答案