Skip to content

Commit

Permalink
Merge pull request #28 from neogranadina/captura
Browse files Browse the repository at this point in the history
Captura
  • Loading branch information
jairomelo authored Jul 23, 2022
2 parents 6bad557 + d843cc5 commit 7bb3c85
Show file tree
Hide file tree
Showing 14 changed files with 2,019 additions and 898 deletions.
5 changes: 3 additions & 2 deletions camcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import configparser
from logcontrol import LogControl as log

CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'setup/config.cfg')
config = configparser.ConfigParser()
config.read(Path('config.cfg'))
config.read(CONFIG_PATH)


class Cam:
Expand Down Expand Up @@ -69,7 +70,7 @@ def cam_order(self):
# write serials in config file
config['camaras']['serial_izq'] = cam1
config['camaras']['serial_der'] = cam2
with open('config.cfg', 'w') as configfile:
with open(CONFIG_PATH, 'w') as configfile:
config.write(configfile)
return {'cam_izq': cam1, 'cam_der': cam2}

Expand Down
17 changes: 16 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@

## [Unreleased]

## [0.1.600] - 2020-04-13
## [0.1.700] - 2022-07-22

Esta versión se dedica a la creación de un sistema para el envío de archivos desde el equipo local hacia un bucket en B2.

### Added

- Se incluyó la capacidad para enviar las imágenes desde el archivo local a B2.
- Agregado un formulario para configurar la aplicación remota de B2.
- Se creó una página para el envío de las imágenes con un solo botón.

### Changed

- Se elimina el archivo .sh para iniciar la aplicación y se creó un archivo .desktop para que se pueda iniciar la aplicación desde el menú de inicio.
- Modificaciones en la ubicación de los archivos de configuración.

## [0.1.600] - 2022-04-13

Esta versión incluye una pantalla de configuración general para los escáners.

Expand Down
3 changes: 2 additions & 1 deletion filecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

# config

CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'setup/config.cfg')
config = configparser.ConfigParser()
config.read(Path('config.cfg'))
config.read(CONFIG_PATH)

# Check compatibility and return images directory

Expand Down
Empty file added filemanager/__init__.py
Empty file.
85 changes: 85 additions & 0 deletions filemanager/b2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import boto3
from botocore.exceptions import ClientError
from botocore.config import Config
from dotenv import load_dotenv
import os
import configparser
from logcontrol import LogControl as log


CONFIG_PATH = os.path.join(os.path.dirname(__file__).replace("/filemanager", ""), 'setup/config.cfg')
print(f"B2 config path: {CONFIG_PATH}")
config = configparser.ConfigParser()
config.read(CONFIG_PATH)

PUBLIC_BUCKET_NAME = config['PROJECT']['project_name'] # establecer en el bucket el nombre del proyecto

LOCAL_DIR = config['DEFAULT']['img_dir'] # debe dirigir a /home/pi/Documents/capturas

class Sync:
def __init__(self):
load_dotenv(os.path.join(os.path.dirname(__file__).replace("/filemanager", ""), 'setup/.env'))
self.endpoint = os.getenv('ENDPOINT')
self.key_id = os.getenv('KEY_ID')
self.app_key = os.getenv('APPLICATION_KEY')

self.b2 = self.get_b2_resource(self.endpoint, self.key_id, self.app_key)


def get_b2_resource(self, endpoint, key_id, app_key):
b2 = boto3.resource(
service_name='s3',
endpoint_url=endpoint,
aws_access_key_id=key_id,
aws_secret_access_key=app_key,
config = Config(
signature_version='s3v4',
))
return b2


def upload_file(self,bucket, directory, file, b2, b2path=None):
file_path = os.path.join(directory, file)
remote_path = b2path if b2path else file
try:
response = b2.Bucket(bucket).upload_file(file_path, remote_path)
except ClientError as e:
print(e.response['Error']['Message'])

return response


def delete_files(self, bucket, keys, b2):
objects = [{'Key': key} for key in keys]
try:
b2.Bucket(bucket).delete_objects(Delete={'Objects': objects})
except ClientError as e:
print(e.response['Error']['Message'])

def sync_dir(self):
# list of files in the bucket
bucket = self.b2.Bucket(PUBLIC_BUCKET_NAME)
keys = [obj.key for obj in bucket.objects.all()]

# print(f'Files in the bucket: {keys}')

# list all filepaths in the local directory
filepaths = []
for root, dirs, files in os.walk(LOCAL_DIR):
for file in files:
filepaths.append(os.path.join(root, file))

# print(f'Files in the local directory: {filepaths}')

for files in filepaths:
remote_dir = os.path.dirname(files).replace(LOCAL_DIR, '').replace('\\', '/')[1:]
filename = os.path.basename(files)
remote_path = f"{remote_dir}/{filename}"
if remote_path not in keys:
print(f'Uploading {files}')
self.upload_file(PUBLIC_BUCKET_NAME, LOCAL_DIR, files, self.b2, remote_path)
else:
print(f'{remote_path} already exists in the bucket')

keys = [obj.key for obj in bucket.objects.all()]
print(f'Files in the bucket: {len(keys)}')
61 changes: 61 additions & 0 deletions imgs/icons/cloud-computing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions imgs/icons/information-button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions imgs/icons/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 22 additions & 2 deletions install_escan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,32 @@ sudo mv /usr/share/gvfs/mounts/gphoto2.mount /usr/share/gvfs/mounts/disable_gpho
sudo mv /usr/share/gvfs/remote-volume-monitors/gphoto2.monitor /usr/share/gvfs/remote-volume-monitors/disable_gphoto2.monitor
sudo mv /usr/lib/gvfs/gvfs-gphoto2-volume-monitor /usr/lib/gvfs/disable_gvfs-gphoto2-volume-monitor

echo crear un acceso directo en el escritorio de pi
echo crear un ejecutable para el escáner
touch /home/pi/Desktop/neo_escan.sh
echo "#!/usr/bin/env bash" >> /home/pi/Desktop/neo_escan.sh
echo "echo abrir Neo Escan" >/home/pi/Desktop/neo_escan.sh
echo "cd ${PWD}" >>/home/pi/Desktop/neo_escan.sh
echo "cd /home/pi/Public/neo_escan" >>/home/pi/Desktop/neo_escan.sh
echo "python3 main.py" >>/home/pi/Desktop/neo_escan.sh
chmod +x /home/pi/Desktop/neo_escan.sh
sudo mkdir /usr/share/neo-escan
sudo mv /home/pi/Desktop/neo_escan.sh /usr/share/neo-escan/neo_escan.sh

echo crear un archivo desktop para la aplicación
touch /home/pi/Desktop/neo_escan.desktop
echo "[Desktop Entry]" >> /home/pi/Desktop/neo_escan.desktop
echo "Encoding=UTF-8" >> /home/pi/Desktop/neo_escan.desktop
echo "Version=1.0" >> /home/pi/Desktop/neo_escan.desktop
echo "Type=Application" >> /home/pi/Desktop/neo_escan.desktop
echo "Terminal=false" >> /home/pi/Desktop/neo_escan.desktop
echo "Name[en]=NeoEscan" >> /home/pi/Desktop/neo_escan.desktop
echo "Comment[en]=Primary Sources Scanner" >> /home/pi/Desktop/neo_escan.desktop
echo "Name[es]=NeoEscan" >> /home/pi/Desktop/neo_escan.desktop
echo "Comment[es]=Escáner para fuentes primarias" >> /home/pi/Desktop/neo_escan.desktop
echo "Exec=/usr/share/neo-escan/neo_escan.sh" >> /home/pi/Desktop/neo_escan.desktop
echo "Icon=/home/pi/Public/neo_escan/imgs/logo.png" >> /home/pi/Desktop/neo_escan.desktop
echo "Category=Cameras;Image Capture;Production;" >> /home/pi/Desktop/neo_escan.desktop

sudo mv /home/pi/Desktop/neo_escan.desktop /usr/share/applications/neo_escan.desktop

echo limpiar archivos de la instalación
rm -rf lua
Expand Down
Loading

0 comments on commit 7bb3c85

Please sign in to comment.