Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add uppercase shortcut for navigation #215

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions osc_tui/createImage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from time import sleep
import oscscreen
from osc_tui import createImage
from osc_tui import main

# All images combo box.
Expand Down
6 changes: 2 additions & 4 deletions osc_tui/createKeyPair.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import oscscreen
from osc_tui import main
from osc_tui import popup
import os

from os.path import expanduser
Expand Down Expand Up @@ -35,9 +34,8 @@ def back():
self.inspector = None

def write_key(path, private_key):
key_file = open(os.path.expanduser(path), 'w')
key_file.write(private_key)
key_file.close()
with open(os.path.expanduser(path), 'w') as key_file :
key_file.write(private_key)

def create():
if(NAME.get_value()):
Expand Down
2 changes: 0 additions & 2 deletions osc_tui/createLoadbalancer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import oscscreen
from osc_tui import main
from osc_tui import popup
import os
from osc_tui import preloader

# NAME input.
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/createSnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ def create():
return
else:
id = ID_LIST[VOLUME_COMBO.get_value()]
volume = VOLUME_COMBO.get_values()[
VOLUME_COMBO.get_value()
]
res = main.GATEWAY.CreateSnapshot(
form=self,
VolumeId=id,
Expand Down
38 changes: 26 additions & 12 deletions osc_tui/createVpcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
# List of all Subregions
SUBREGION = None

import sys
Fixed Show fixed Hide fixed

def print_error(*args, **kwargs):
error_log_file = "error_log.txt"
with open(error_log_file, "a") as error_log:
print(*args, file=sys.stderr, **kwargs)
print(*args, file=error_log, **kwargs)

class createVpcs(oscscreen.FormBaseNew):
def __init__(self, *args, **keywords):
Expand All @@ -33,11 +40,14 @@ def back():
self.inspector = None

def create():
cidr = CIDR.get_value()
res = main.GATEWAY.CreateNet(
form=self,
IpRange=cidr,
)
cidr_value = CIDR.get_value()
if cidr_value:
res = main.GATEWAY.CreateNet(
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
form=self,
IpRange=cidr_value,
)
else:
print_error('CIDR value is missing')
back()

global CIDR
Expand Down Expand Up @@ -73,13 +83,17 @@ def back():
self.inspector = None

def create():
cidr = CIDRSUBNET.get_value()
res = main.GATEWAY.CreateSubnet(
form=self,
IpRange=cidr,
NetId=popup.SUBNETID,
SubregionName=SUBREGION.get_values()[SUBREGION.get_value()],
)
cidr_value = CIDRSUBNET.get_value()
subregion_value = SUBREGION.get_values()[SUBREGION.get_value()]
if cidr_value and subregion_value:
res = main.GATEWAY.CreateSubnet(
Fixed Show fixed Hide fixed
form=self,
IpRange=cidr_value,
NetId=popup.SUBNETID,
SubregionName=subregion_value,
)
else:
print_error('CIDR value or Subregion is missing')
back()

global CIDR
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/flexibleGPU.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine

class Grid(selectableGrid.SelectableGrid):
def __init__(self, screen, *args, **keywords):
Expand Down
30 changes: 15 additions & 15 deletions osc_tui/guiRules.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ def objectify():
ret = None
if os.path.isfile(PATH):
ret = {}
configFile = open(PATH)
j = json.loads(configFile.read())
for rule_name in j:
rule=j[rule_name]
if "mode" not in rule:
print('"mode" is a requirre argument of costum rule',
file=sys.stderr)
if rule["mode"] not in ret:
ret[rule["mode"]] = {}
ret[rule["mode"]][rule_name] = {
"ports": rule["ports"],
"protocols": rule["protocols"]
}
if "ips" in rule:
ret[rule["mode"]][rule_name]["ips"] = rule["ips"]
with open(PATH) as configFile :
j = json.loads(configFile.read())
for rule_name in j:
rule=j[rule_name]
if "mode" not in rule:
print('"mode" is a requirre argument of costum rule',
file=sys.stderr)
if rule["mode"] not in ret:
ret[rule["mode"]] = {}
ret[rule["mode"]][rule_name] = {
"ports": rule["ports"],
"protocols": rule["protocols"]
}
if "ips" in rule:
ret[rule["mode"]][rule_name]["ips"] = rule["ips"]
return ret

def parse():
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/imageGrid.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import oscscreen
import pyperclip
import time

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class ImageGrid(selectableGrid.SelectableGrid):
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/instancesGrid.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import time

import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/keyPairsGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class KeyPairsGrid(selectableGrid.SelectableGrid):
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/loadbalancerGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class loadbalancerGrid(selectableGrid.SelectableGrid):
Expand Down
2 changes: 0 additions & 2 deletions osc_tui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from osc_tui import profileSelector
from osc_tui import guiRules

import time

# GLOBALS ATTRIBUTES
APP = None
GATEWAY = None
Expand Down
27 changes: 24 additions & 3 deletions osc_tui/mainForm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import ipaddress

import oscscreen
import pyperclip

import graphviz

Expand All @@ -27,10 +26,8 @@
from osc_tui import popup
from osc_tui import securityGroupsGrid
from osc_tui import securityRulesGrid
from osc_tui import selectableGrid
from osc_tui import snapshotGrid
from osc_tui import loadbalancerGrid
from osc_tui import virtualMachine
from osc_tui import volumesGrid
from osc_tui import guiRules

Expand Down Expand Up @@ -355,12 +352,36 @@ def quit_key(form, key_val):
def key_reload(form, _):
form.reload()

def switch_to_volumes(form, _):
Fixed Show fixed Hide fixed
global MODE
MODE = "Volumes"
form.reload()

def switch_to_instances(form, _):
Fixed Show fixed Hide fixed
global MODE
MODE = "Vms"
form.reload()

def switch_to_images(form, _):
Fixed Show fixed Hide fixed
global MODE
MODE = "Images"
form.reload()

def switch_to_security_grid(form, _):
Fixed Show fixed Hide fixed
global MODE
MODE = "Security"
form.reload()

def set_up_handlers(self):
super().set_up_handlers()
self.add_handlers({"q": self.quit_key})
self.add_handlers({"^Q": quit})
self.add_handlers({"h": popup.showHelp})
self.add_handlers({"/": popup.slashSearch})
self.add_handlers({"V": self.switch_to_volumes})
self.add_handlers({"I": self.switch_to_instances})
self.add_handlers({"M": self.switch_to_images})
self.add_handlers({"S": self.switch_to_security_grid})
self.add_handlers({
"r" : self.key_reload,
curses.KEY_F5 : self.key_reload
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/netAccesssPoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import oscscreen
import pyperclip

from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
Expand Down
6 changes: 0 additions & 6 deletions osc_tui/netPeering.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine

class Grid(selectableGrid.SelectableGrid):
def __init__(self, screen, *args, **keywords):
Expand Down
19 changes: 10 additions & 9 deletions osc_tui/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ def remove_cb():


def addSecurityGroupToVm(form, form_color='STANDOUT'):
main.SECURITY_GROUP
F = ConfirmCancelPopup(name='Add New Security Group', color=form_color)
F.preserve_selected_widget = True
groups = main.VM["SecurityGroups"]
Expand Down Expand Up @@ -674,7 +673,6 @@ def instances_registered():
)

def delete_cb():
val = main.GATEWAY.DeleteLoadBalancer(LoadBalancerName=name)
form.current_grid.h_refresh(None)
exit()

Expand Down Expand Up @@ -778,7 +776,6 @@ def associateRoutetable():
exit()

def delete_cb():
val = main.GATEWAY.DeleteSubnet(SubnetId=name)
form.current_grid.h_refresh(None)
exit()
delete.whenPressed = delete_cb
Expand Down Expand Up @@ -1065,12 +1062,16 @@ def showHelp(arg):
oscscreen.Pager,
)
ft.values = [
"Return to profile : q",
"Exit : Ctrl+Q",
"Refresh : F5 or r",
"Search in Fields : /",
"search in Menu : l",
"Help : h\n",
"Return to profile : q",
"Exit : Ctrl+Q",
"Refresh : F5 or r",
"Search in Fields : /",
"search in Menu : l",
"Help : h\n",
"Switch to Vms : I",
"Switch to Volumes : V",
"Switch to Images : M",
"Switch to Security : S",
]

def ok():
Expand Down
1 change: 0 additions & 1 deletion osc_tui/profileSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
from pathlib import Path
import threading
from osc_tui import preloader

import oscscreen
Expand Down
3 changes: 0 additions & 3 deletions osc_tui/securityGroupsGrid.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@

import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class SecurityGroupsGrid(selectableGrid.SelectableGrid):
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/securityRulesGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

from osc_tui import createVm
from osc_tui import main
import oscscreen
from osc_tui import popup
import pyperclip
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class SecurityRulesGrid(selectableGrid.SelectableGrid):
Expand Down
2 changes: 0 additions & 2 deletions osc_tui/selectableGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import curses
import threading
import time

import oscscreen

from osc_tui import main
from osc_tui import popup
from osc_tui import mainForm

# Initially it was designed to have a thread that auto refresh... However, even if it worked fine, if too many people does it, it looks like a DDOS attack.
Expand Down
5 changes: 0 additions & 5 deletions osc_tui/snapshotGrid.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import oscscreen
import pyperclip

from osc_tui import createVm
from osc_tui import main
from osc_tui import popup
from osc_tui import selectableGrid
from osc_tui import virtualMachine


class SnapshotGrid(selectableGrid.SelectableGrid):
Expand Down
Loading