Browse Source

Merge branch 'release/0.4.0'

liuyuqi-dellpc 5 months ago
parent
commit
6e4a48ffdc
5 changed files with 69 additions and 10 deletions
  1. 6 1
      README.md
  2. 23 4
      auto_commit/auto_commit.py
  3. 1 1
      auto_commit/options.py
  4. 17 4
      main.py
  5. 22 0
      scripts/start_auto_commit.bat

+ 6 - 1
README.md

@@ -1,6 +1,11 @@
 # auto_commit
 
-批量提交代码,实现多项目版本管理
+批量git commit,push/pull代码,实现多项目版本管理
+
+```
+auto_commit commit --path <curpath>
+auto_commit sync --path <curpath>
+```
 
 ## License
 

+ 23 - 4
auto_commit/auto_commit.py

@@ -18,13 +18,22 @@ class AutoCommit(object):
     def _commit(self, path):
         """ git commit """
         os.chdir(path)
-        print(f"{bcolors.OKGREEN}commiting {path}{bcolors.ENDC}")
+        print(f"{bcolors.OKGREEN} commiting {path}{bcolors.ENDC}")
         os.system("git add .")
         os.system("git commit -m \"Automatic Commit By liuyuqi\"")
-        print(f"{bcolors.OKGREEN}commit success{bcolors.ENDC}")
+        print(f"{bcolors.OKGREEN} commit finish{bcolors.ENDC}")
         # os.chdir(work_dir)
 
-    def run(self):
+    def _sync(self, path):
+        """ git pull """
+        os.chdir(path)
+        print(f"{bcolors.OKGREEN} syncing {path}{bcolors.ENDC}")
+        os.system("git pull")
+        os.system("git push")
+        print(f"{bcolors.OKGREEN} sync finish{bcolors.ENDC}")
+        # os.chdir(work_dir)
+
+    def commit(self):
         """ run """
         if ".git" in os.listdir(self.params['path']):
             self._commit(self.params['path'])
@@ -32,4 +41,14 @@ class AutoCommit(object):
             for root, dirs, files in os.walk(self.params['path']):
                 if ".git" in dirs:
                     self._commit(root)
-        os.system("pause")
+        os.system("pause")
+    
+    def sync(self):
+        """ sync """
+        if ".git" in os.listdir(self.params['path']):
+            self._sync(self.params['path'])
+        else:
+            for root, dirs, files in os.walk(self.params['path']):
+                if ".git" in dirs:
+                    self._sync(root)
+        os.system("pause")

+ 1 - 1
auto_commit/options.py

@@ -23,7 +23,7 @@ def parse_args():
                                      ''', epilog="Believe that with the above description, " +
                                                             "you can start working right away. Wish you success")
     # group = parser.add_mutually_exclusive_group()
-    # parser.add_argument('command',  help='command: crawl, download', choices=['crawl','download', 'help','version'] , default='help')
+    parser.add_argument('cmd',  help='cmd: commit, sync', choices=['commit','sync', 'help','version'] , default='help')
     parser.add_argument('--path', help='set a path')
     args = parser.parse_args()
 

+ 17 - 4
main.py

@@ -6,16 +6,29 @@
 @License :   Copyright © 2017-2022 liuyuqi. All Rights Reserved.
 @Desc    :   enter point
 """
+from regex import P
 from auto_commit.utils.colors import bcolors
 from auto_commit.auto_commit import AutoCommit
 from auto_commit.options import parse_args
 
 if __name__=='__main__':
     args = parse_args()
+    print(args['cmd'])
     try:
-        if args['path'] is not None:
-            auto_commit = AutoCommit(params=args)
-            auto_commit.run()
-    except:
+        if args['path'] is not None and args['cmd'] is not None:
+            if args['cmd'] == 'commit':
+                auto_commit = AutoCommit(params=args)
+                auto_commit.commit()
+            elif args['cmd'] == 'sync':
+                auto_commit = AutoCommit(params=args)
+                auto_commit.sync()
+            elif args['cmd'] == 'help':
+                print('help')
+            elif args['cmd'] == 'version':
+                print('version')
+            else:
+                print(f"{bcolors.FAIL}Please input path {bcolors.ENDC}")
+    except Exception as e:
+        print(e)
         print(f"{bcolors.FAIL}Please input path {bcolors.ENDC}")
 

+ 22 - 0
scripts/start_auto_commit.bat

@@ -0,0 +1,22 @@
+@echo off
+REM ***************************************************************************
+REM @Contact :   liuyuqi.gov@msn.cn
+REM @Time    :   2024/07/22 14:44:35
+REM @Version :   1.0
+REM @License :   (C)Copyright 2019 liuyuqi.
+REM @Desc    :   引导输入一个路径,执行 auto_commit.exe
+REM %1 - ext_name
+REM %2 - characters replaced
+REM %3 - new characters
+REM ***************************************************************************
+
+setlocal
+set ext_name=%1
+set characters_replaced=%2
+set new_characters=%
+
+echo.
+echo "please input a path:"
+set /p path=
+    
+call auto_commit.exe --path %path%