diff --git a/README.md b/README.md index e4f2d74..cfe8f5b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # juniper-config-to-set Converts Juniper Networks configurations to a series of set commands -Parser in PHP by Tim Price, rewrite in Python with enhancements by rick@gnous.eu +Parser in PHP by Tim Price, rewrite in JavaScript by rick@gnous.eu -First, install PyQt with `pip3 install -r requirements.txt`. You can juste type `python3 gui.py` to open the program and enter text ! - -If you want parse a file, use `python3 cli.py -f file`. +Just download the depot and open `index.html` into your favorite browser. diff --git a/cli.py b/cli.py deleted file mode 100644 index 6efd4f5..0000000 --- a/cli.py +++ /dev/null @@ -1,41 +0,0 @@ -########## -# IMPORT # -########## -import argparse -from os.path import exists, isfile -from parser import ParserJuniper - -__author__ = "rick@gnous.eu" -__licence__ = "GPL3" - -parserJuniper = ParserJuniper() -parserArg = argparse.ArgumentParser( - description="Parse a Juniper conf file and print the series of set commands for." - ) -parserArg.add_argument("-f", "--file", nargs=1, required=True, type=str, help="The conf file.") -parserArg.add_argument("-o", "--output", nargs=1, type=str, help="The output file.") - -arg = parserArg.parse_args() - -inputFile = str(arg.file[0]) -outputFile = None -if arg.output: - outputFile = str(arg.output[0]) - if exists(outputFile) and isfile(outputFile): - writeOverFile = input("The file already exists, write over it ? o/O") - if writeOverFile.lower() != 'o': - print("STOP EVERYTHING!!!!!!!!!!!!!") - exit(0) - elif exists(outputFile): - print("The output musts be a file.") - exit(0) - -if exists(inputFile) and isfile(inputFile): - parseResul = parserJuniper.parseFile(inputFile) - if outputFile: - with open(outputFile, 'w') as file: - file.write(parseResul) - else: - print(parseResul) -else: - print("Pass an existing file.") diff --git a/controllers/controller.py b/controllers/controller.py deleted file mode 100644 index df54de3..0000000 --- a/controllers/controller.py +++ /dev/null @@ -1,36 +0,0 @@ -########## -# IMPORT # -########## -from PyQt5.QtWidgets import QTextEdit, QTextBrowser -from parser import ParserJuniper - -__author__ = "rick@gnous.eu" -__licence__ = "GPL3" - -class Controller: - def __init__(self, inputText, outputText): - """ - Init the controller - - :param inputText QTextEdit: the area where Juniper conf in write - :param outputText QTextBrowser: area where a series of set - command is showed - """ - self.inputText = inputText - self.outputText = outputText - self.parser = ParserJuniper() - - def click(self): - """ - Called when the user press the Parse button. - Gets the text of inputText and parse it. Shows the result on - outputText. - """ - self.parser.resetTree() - textToParse = self.inputText.toPlainText() - parsedText = "" - for line in textToParse.splitlines(): - textConf = self.parser.parse(line) - if textConf: - parsedText += textConf + "\n" - self.outputText.setText(parsedText) diff --git a/gui.py b/gui.py deleted file mode 100644 index 03c7429..0000000 --- a/gui.py +++ /dev/null @@ -1,36 +0,0 @@ -########## -# IMPORT # -########## -from sys import argv -from PyQt5 import uic -from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QTextEdit,\ - QTextBrowser -from controllers.controller import Controller - -__author__ = "rick@gnous.eu" -__licence__ = "GPL3" - -class Interface(QMainWindow): - def __init__(self): - super(Interface, self).__init__() - - self.setWindowTitle("Parser Juniper") - self.ui = uic.loadUi("views/principal.ui") - self.setCentralWidget(self.ui) - - inputText = self.ui.findChildren(QTextEdit, "inputText")[0] - outputText = self.ui.findChildren(QTextBrowser, "outputText")[0] - parseButton = self.ui.findChildren(QPushButton, "parse")[0] - quitButton = self.ui.findChildren(QPushButton, "quit")[0] - - self.controller = Controller(inputText, outputText) - - parseButton.clicked.connect(self.controller.click) - quitButton.clicked.connect(quit) - - self.show() - -if __name__ == "__main__": - app = QApplication(argv) - window = Interface() - exit(app.exec_()) diff --git a/parser.py b/parser.py deleted file mode 100644 index c4befe6..0000000 --- a/parser.py +++ /dev/null @@ -1,64 +0,0 @@ -# Tom Price writes the program in PHP here : https://github.com/pgnuta/juniper-config-to-set -# I adapt it in Python and add some enhancements -__author__ = "Tim Price | rick@gnous.eu" -__licence__ = "GPL3" - -class ParserJuniper: - def __init__(self): - self.tree = [] - - def resetTree(self): - self.tree = [] - - def printTree(self, tree): - return ''.join(map(str, tree)) - - def parse(self, line): - """ - Parse a line of conf - - :param line str: line will be parse - :ret str: a parse string, empty if its a comment - """ - ret = "" - line = line.strip() - if not line.startswith('#'): - if '#' in line: - line, comment = line.split('#', 1) - line = line.strip() - - if line.endswith(';'): - line = line[:-1] - - if not self.tree: - ret = "set " + line - else: - ret = "set " + self.printTree(self.tree) + line - - if line.endswith('{'): - line = line[:-1] - self.tree.append(line) - - if line.endswith('}'): - self.tree.pop() - - return ret - - def parseFile(self, path): - """ - parse a file and return the commands - - :param path str: the path to file - :ret str: the series of set commands - """ - ret = "" - with open(path, 'r') as file: - self.resetTree() - for line in file: - lineConf = self.parse(line) - if lineConf: - ret += lineConf + "\n" - return ret - -#parser = ParserJuniper() -#parser.parseFile("test") diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 65050c9..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -PyQt5==5.10.1 diff --git a/views/principal.ui b/views/principal.ui deleted file mode 100644 index 1c12d34..0000000 --- a/views/principal.ui +++ /dev/null @@ -1,78 +0,0 @@ - - - MainWindow - - - - 0 - 0 - 800 - 550 - - - - MainWindow - - - - - - 20 - 20 - 361 - 391 - - - - - - - 420 - 430 - 131 - 41 - - - - Parse ! - - - - - - 420 - 20 - 351 - 391 - - - - - - - 250 - 430 - 131 - 41 - - - - Quit - - - - - - - 0 - 0 - 800 - 20 - - - - - - - -