Przeglądaj źródła

判断参数是否存在

JeffWang 3 lat temu
rodzic
commit
723f63dfea
1 zmienionych plików z 9 dodań i 8 usunięć
  1. 9 8
      自动编译系统脚本标准化/builder.py

+ 9 - 8
自动编译系统脚本标准化/builder.py

@@ -102,14 +102,15 @@ def prev_compile():
         return False
     
     # Python无法将字符串'false'转为布尔类型;
-    if type(PREV_ARG['sync']) == type(u'str'):
-        PREV_ARG['sync'] = True if PREV_ARG['sync'].lower() == u'true' else False
+    if 'sync' in PREV_ARG:
+        if type(PREV_ARG['sync']) == type(u'str'):
+            PREV_ARG['sync'] = True if PREV_ARG['sync'].lower() == u'true' else False
+        print(type(PREV_ARG['sync']), PREV_ARG['sync'])
 
-    if type(PREV_ARG['redownload']) == type(u'str'):
-        PREV_ARG['redownload'] = True if PREV_ARG['redownload'].lower() == u'true' else False
-			
-    print(type(PREV_ARG['sync']), PREV_ARG['sync'])
-    print(type(PREV_ARG['redownload']), PREV_ARG['redownload'])
+    if 'redownload' in PREV_ARG:
+        if type(PREV_ARG['redownload']) == type(u'str'):
+            PREV_ARG['redownload'] = True if PREV_ARG['redownload'].lower() == u'true' else False
+        print(type(PREV_ARG['redownload']), PREV_ARG['redownload'])
 
     # 更新代码;
     commands=None
@@ -120,7 +121,7 @@ def prev_compile():
     
     # 重新下载;
     commands=[]
-    if PREV_ARG['redownload']:
+    if 'redownload' in PREV_ARG and PREV_ARG['redownload']:
         print("start redownload")
         commands.append("export PATH=$PATH:/bin/git-repo/")
         commands.append(str.format("cd %s") % CODE_DIR)