Skip to content

Commit

Permalink
Add several basic mass commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaudov, Stanislav Tomov committed Jun 16, 2020
1 parent 1eb8f7c commit 30720fd
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
12 changes: 10 additions & 2 deletions code_manager/commands/commit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import subprocess
import sys

import code_manager.utils.logger

class CommitCommand:

name = 'commit'

def __init__(self):
pass

def execute(self, arguments, root):
pass
def execute(self, args, path):
if not os.path.exists(os.path.join(path, '.git')):
return 0
ret = subprocess.run(['git', 'commit', *args], stdout=subprocess.STDOUT, cwd=path)
return 0


ExportedClass = CommitCommand
14 changes: 9 additions & 5 deletions code_manager/commands/grep.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import subprocess
import sys

import code_manager.utils.logger

class GrepCommand:

name = 'grep'

def __init__(self):
pass

def execute(self, args, path):

ret = subprocess.run(['git', '-C', path, 'grep', *args], stdout=subprocess.PIPE)
return path, ret.returncode, ret.stdout
ret = subprocess.run(['grep', '-r', *args], stdout=subprocess.PIPE, cwd=path)

for line in ret.stdout.splitlines():
sys.stdout.buffer.write(bytes(self.pack + ':', 'utf-8') + line + b'\n')
sys.stdout.buffer.flush()

return 0


ExportedClass = GrepCommand
12 changes: 10 additions & 2 deletions code_manager/commands/pull.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import subprocess
import sys

import code_manager.utils.logger

class PullCommand:

name = 'pull'

def __init__(self):
pass

def execute(self, arguments, root):
pass
def execute(self, args, path):
if not os.path.exists(os.path.join(path, '.git')):
return 0
ret = subprocess.run(['git', 'pull', *args], stdout=subprocess.STDOUT, cwd=path)
return 0


ExportedClass = PullCommand
18 changes: 12 additions & 6 deletions code_manager/commands/push.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
class PushCommand:
import subprocess
import os
import sys

name = 'push'
import code_manager.utils.logger

def __init__(self):
pass
class PushCommand:

def execute(self, arguments, root):
pass
name = 'push'

def execute(self, args, path):
if not os.path.exists(os.path.join(path, '.git')):
return 0
ret = subprocess.run(['git', 'push', *args], stdout=subprocess.STDOUT, cwd=path)
return 0


ExportedClass = PushCommand
13 changes: 8 additions & 5 deletions code_manager/commands/sed.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import subprocess
import sys

import code_manager.utils.logger

class SedCommand:

name = 'sed'

def __init__(self):
pass

def execute(self, arguments, root):
pass
def execute(self, args, path):
ret = subprocess.run(['sed', *args], stdout=subprocess.PIPE, cwd=path)
return 0


ExportedClass = SedCommand
5 changes: 3 additions & 2 deletions code_manager/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,9 @@ def run_command(self, command, args):
self.commands.load_commands()
for pack, _ in self.packages.items():

if not self.cache.is_installed(pack):
if not self.cache.is_fetched(pack):
continue

root = os.path.join(self.code_dir, self._get_root(pack))
self.commands.execute_command(command, args, pack, root)
return 0
return 0
2 changes: 1 addition & 1 deletion code_manager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ def main():
args, _ = parser.parse_known_args()
opt = configparser.ConfigParser()

if '--' in args.rest:
if hasattr(args, 'rest') and '--' in args.rest:
args.rest.remove('--')

copy_config()
Expand Down

0 comments on commit 30720fd

Please sign in to comment.