This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb83800
commit 1a9d4ca
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Tool functions | ||
""" | ||
|
||
import sys | ||
from subprocess import run, PIPE | ||
from loon.utils import isfile, isdir, read_csv | ||
|
||
|
||
def batch(input, cmds, sep=',', header=False, dry_run=False, _logger=None): | ||
"""Batch process commands according to mappings from file""" | ||
if not isfile(input): | ||
print("Error: file %s does not exist" % input) | ||
sys.exit(1) | ||
|
||
data = read_csv(input, sep=sep, rm_comment=True) | ||
if not header: | ||
# Remove header | ||
_ = data.pop(0) | ||
|
||
cmd_list = [] | ||
for row in data: | ||
cmd_list.append(cmds.format(*row)) | ||
for cmd in cmd_list: | ||
print("=> Running %s" % cmd) | ||
if not dry_run: | ||
run_res = run(cmd, shell=True) | ||
_logger.info("Status code: " + str(run_res.returncode)) | ||
if run_res.returncode != 0: | ||
print("Error: some error occurred, please check the info!") | ||
sys.exit(run_res.returncode) | ||
|
||
return |