Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@eager
def _parse_apt_operations(help_text_lines):
is_commands_list = False
for line in help_text_lines:
line = line.decode().strip()
if is_commands_list and line:
yield line.split()[0]
elif line.startswith('Basic commands:') \
or line.startswith('Most used commands:'):
is_commands_list = True
@eager
def _get_cask_install_lines(output):
for line in output.split('\n'):
line = line.strip()
if line.startswith('brew cask install'):
yield line
@eager
def _get_available_commands(stdout):
commands_listing = False
for line in stdout.split('\n'):
if line.startswith('where is one of:'):
commands_listing = True
elif commands_listing:
if not line:
break
for command in line.split(', '):
stripped = command.strip()
if stripped:
yield stripped
@eager
def _get_all_tasks(gradle):
proc = Popen([gradle, 'tasks'], stdout=PIPE)
should_yield = False
for line in proc.stdout.readlines():
line = line.decode().strip()
if line.startswith('----'):
should_yield = True
continue
if not line.strip():
should_yield = False
continue
if should_yield and not line.startswith('All tasks runnable from root project'):
yield line.split(' ')[0]
@eager
def _get_possible_interfaces():
proc = subprocess.Popen(['ifconfig', '-a'], stdout=subprocess.PIPE)
for line in proc.stdout.readlines():
line = line.decode()
if line and line != '\n' and not line.startswith(' '):
yield line.split(' ')[0]
@eager
def _get_all_commands():
proc = subprocess.Popen(['gem', 'help', 'commands'],
stdout=subprocess.PIPE)
for line in proc.stdout.readlines():
line = line.decode()
if line.startswith(' '):
yield line.strip().split(' ')[0]
@eager
def _get_between(content, start, end=None):
should_yield = False
for line in content.split('\n'):
if start in line:
should_yield = True
continue
if end and end in line:
return
if should_yield and line:
yield line.strip().split(' ')[0]
@eager
def get_new_command(command):
output = command.output.strip()
if is_arg_url(command):
yield command.script.replace('open ', 'open http://')
elif output.startswith('The file ') and output.endswith(' does not exist.'):
arg = command.script.split(' ', 1)[1]
for option in ['touch', 'mkdir']:
yield shell.and_(u'{} {}'.format(option, arg), command.script)
@eager
def _parse_apt_get_and_cache_operations(help_text_lines):
is_commands_list = False
for line in help_text_lines:
line = line.decode().strip()
if is_commands_list:
if not line:
return
yield line.split()[0]
elif line.startswith('Commands:'):
is_commands_list = True
@eager
def _get_all_environments():
root = Path('~/.virtualenvs').expanduser()
if not root.is_dir():
return
for child in root.iterdir():
if child.is_dir():
yield child.name