Skip to content

Commit

Permalink
Merge pull request #1 from septentrio-gnss/dev-branch
Browse files Browse the repository at this point in the history
Merge dev branch to Main
  • Loading branch information
Arno-Balois authored Jun 25, 2024
2 parents abc40b3 + f5a151f commit 1686830
Show file tree
Hide file tree
Showing 36 changed files with 4,515 additions and 3,712 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ var/
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
*.spec
*.exe
23 changes: 7 additions & 16 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Pydatalink is an application whose functions are similar to RxTools' Datalink, b

The second major feature of this version is that the code is entirely open source, unlike the Datalink code. The aim of making the project available as open source is to allow the community to contribute to the development of the tool in order to integrate new functionalities.
<div align="center">
<img src="doc_sources/pyDatalink.PNG" width="75%">
<img src="doc_sources/pyDatalink.PNG" >
</div>
<br>

Expand Down Expand Up @@ -84,28 +84,19 @@ Once you've installed python, all you have to do is download the source code and

### Using git clone
```
git clone https://github.com/septentrio-gnss/DataLink.git
cd DataLink
git clone https://github.com/septentrio-gnss/Septentrio-PyDataLink.git
cd Septentrio-PyDataLink
```
### using GitHub
- First click on **code**.<br>
- Then click on **dowload Zip**
### (Optional) Create a Virtual environement
This will allow you to create a contained workspace where every python package will be installed
```
python -m venv venv
source venv/bin/activate
```
### Install Python packages
```
pip install -r requirements.txt
```
### Run pyDatalink

By default pyDatalink run as a Graphical interface
## Build the project
to build and generate the executable file , run the folowing command
```
python pyDatalinkApp.py
python build.py
```
After the build is successfully completed , a executable file will be generated

<br>

Expand Down
61 changes: 61 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import subprocess
import sys
import shutil
import venv
from src.constants import *

# Define paths and script name
script_name = MAINSCRIPTPATH
icon_path = os.path.join(DATAFILESPATH, 'pyDatalink_icon.ico')
output_directory = PROJECTPATH
requirements_file = 'requirements.txt'
spec_file = APPNAME + ".spec"
venv_dir = 'venv'



print("Create a virtual environment")
venv.create(venv_dir, with_pip=True)

print("Activate virtual environment")
activate_script = os.path.join(venv_dir, 'Scripts', 'activate') if sys.platform == 'win32' else os.path.join(venv_dir, 'bin', 'activate')

print("Install required python packages")
subprocess.run([sys.executable, '-m', 'pip', 'install', '-r', requirements_file])

print("Create the executable")
pyinstaller_command = [
'pyinstaller',
'--name=' + APPNAME,
'--onefile',
'--icon=' + icon_path,
'--distpath=' + output_directory,
'--clean',
'--noconfirm',
"--noconsole",
"--add-data=" + DATAFILESPATH +";data",
script_name
]

status = subprocess.run(pyinstaller_command)

if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists(spec_file):
os.remove(spec_file)

if sys.platform == 'win32':
deactivate_script = os.path.join(venv_dir, 'Scripts', 'deactivate.bat')
else:
deactivate_script = os.path.join(venv_dir, 'bin', 'deactivate')


subprocess.run(deactivate_script, shell=True)


shutil.rmtree(venv_dir)
if status.returncode == 0 :
print("Build completed successfully!")
else :
print("Error while building the project")
8 changes: 4 additions & 4 deletions dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ yes , The very purpose of this project is to remake a version of pydatalink with
# What is pyDatalink

<div align="center">
<img src="doc_sources/pyDatalink.PNG" width="75%">
<img src="doc_sources/pyDatalink.PNG" >
</div>

<br>
Expand Down Expand Up @@ -164,8 +164,8 @@ Once you've installed python, all you have to do is download the source code and

### Using git clone
```
git clone https://github.com/septentrio-gnss/DataLink.git
cd DataLink
git clone https://github.com/septentrio-gnss/Septentrio-PyDataLink.git
cd Septentrio-PyDataLink
```
### using GitHub
- First click on **code**.<br>
Expand All @@ -184,7 +184,7 @@ pip install -r requirements.txt

By default pyDatalink run as a Graphical interface
```
python pyDatalinkApp.py
python pyDatalink.py
```

# User Manual
Expand Down
5 changes: 0 additions & 5 deletions dev/Todo

This file was deleted.

Binary file modified dev/doc_sources/pyDatalink.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc_sources/pyDatalink.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
157 changes: 157 additions & 0 deletions pyDatalink.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#!/usr/bin/env python
# ###############################################################################
#
# Copyright (c) 2024, Septentrio
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import sys
import os
import argparse
from src.constants import DATAPATH , CONFIGPATH , LOGFILESPATH , DEFAULTCONFIGFILE , MAXFILENUMBER
from src.StreamConfig.App import App , ConfigurationType
try :
from PySide6.QtWidgets import QApplication
from src.UserInterfaces.GraphicalUserInterface import GraphicalUserInterface
GUI = True
except Exception as e:
GUI = False
raise e

try :
from src.UserInterfaces.TerminalUserInterface import TerminalUserInterface
TUI = True
except NotImplementedError :
TUI = False

from src.UserInterfaces.CommandLineInterface import CommandLineInterface

def clean_log_folder():
files = [os.path.join(LOGFILESPATH, f) for f in os.listdir(LOGFILESPATH) if os.path.isfile(os.path.join(LOGFILESPATH, f))]
while len(files) > MAXFILENUMBER:
oldest_file = min(files, key=os.path.getctime)
os.remove(oldest_file)
files = [os.path.join(LOGFILESPATH, f) for f in os.listdir(LOGFILESPATH) if os.path.isfile(os.path.join(LOGFILESPATH, f))]



def check_data_folder():
if os.path.exists(DATAPATH) is not True :
os.mkdir(DATAPATH)
if os.path.exists( CONFIGPATH ) is not True:
os.mkdir(CONFIGPATH )
if os.path.exists( LOGFILESPATH ) is not True:
os.mkdir(LOGFILESPATH )
else :
clean_log_folder()

class DatalinkApp:
"""Main class for Datalink application
"""

def __init__(self , config_args) -> None:
self.config_args = config_args
self.app : App = None
self.user_interface = None
self.show_data_port = None
if self.config_args.Mode == "CMD" :
if self.config_args.Streams is None :
print("Error : you need to specify the streams to configure\n")
return
else :
if self.config_args.ShowData is not None:
try :
show = int(self.config_args.ShowData)
except ValueError as exc:
print(f"Error : streams stream_id \"{self.config_args.ShowData}\" is not correct , please enter a valid ID !")
raise exc

self.app = App(max_stream=len(self.config_args.Streams),stream_settings_list=self.config_args.Streams , configuration_type= ConfigurationType.CMDLINE)
if self.config_args.ShowData is not None :
if show <= len(self.app.stream_list):
self.show_data_port=self.app.stream_list[show - 1]
self.show_data_port.toggle_all_data_visibility()

else :
if os.path.exists(self.config_args.ConfigPath):
self.app = App(configuration_type= ConfigurationType.FILE,config_file=self.config_args.ConfigPath, debug_logging=True)
elif os.path.exists(DEFAULTCONFIGFILE) :
self.app = App(configuration_type= ConfigurationType.FILE , config_file=DEFAULTCONFIGFILE , debug_logging=True)
else :
self.app = App(debug_logging=True)

def start(self) -> None :
if self.config_args.Mode == "TUI":
self.datalink__terminal_start()
elif self.config_args.Mode == "GUI":
self.datalink_graphical_start()
elif self.config_args.Mode == "CMD":
self.datalink_cmdline_start()

def datalink__terminal_start(self):
"""Start Datalink as a Graphical User interface
"""
if os.name == "posix" and TUI:
self.user_interface = TerminalUserInterface(self.app)
sys.exit(self.user_interface.MainMenu())
elif not TUI:
print("simple-Term-menu is required to run in TUI mode \nInstall Simple-Term-Menu : pip install simple-term-menu\nOr run the App in a Different mode (-m GUI or -m CMD)")
else :
print("Sorry the terminal version of Data link is only available on Unix distro")

def datalink_graphical_start(self):
"""Start Datalink as a Graphical User interface
"""
if(GUI):
self.user_interface = QApplication()
gallery = GraphicalUserInterface(self.app)
gallery.show()
sys.exit(self.user_interface.exec())
else :
print("PySide6 is required to run in GUI mode \nInstall pyside : pip install PySide6 \nOr run the App in a Different mode (-m CMD or -m TUI)")

def datalink_cmdline_start(self):
"""Start Datalink as a command line interface
"""
self.user_interface = CommandLineInterface(self.app , show_data_id= self.show_data_port)
sys.exit(self.user_interface.run())

if __name__ == "__main__":
check_data_folder()

parser = argparse.ArgumentParser(prog="PyDatalink" ,description='')
parser.add_argument('--Mode','-m', choices=['TUI', 'GUI', 'CMD'], default='GUI',
help="Start %(prog)s with a specific interface (DEFAULT : GUI)")
parser.add_argument('--ConfigPath','-c', action='store', default= DEFAULTCONFIGFILE ,
help='Path to the config file ( This Option won\'t be use when in CMD mode ) ')

parser.add_argument('--Streams' ,'-s', nargs='*' , action='store' ,
help="List of streams to configure , the size of this list is configure by --nbPorts\n ,this parameter is only used when in CMD mode \n ")
parser.add_argument('--ShowData', "-d" ,nargs="?", action="store",
help="Lisf of streams stream_id, will print every input and output data from the streams\n ,this parameter is only used when in CMD mode ")

DatalinkApp(config_args=parser.parse_args()).start()

Loading

0 comments on commit 1686830

Please sign in to comment.