Esempio n. 1
0
    def transfer_audio(self, moth_mount_path:str, audio_path:str, e: event):
        success, filenameList = self.list_files(moth_mount_path)

        if success:
            # Copy over only the relevant audio files
            for filepath in filenameList:
                try:
                    filename = filepath.lstrip(f'{moth_mount_path}/')
                    filedate = self.filename_to_date(filename)
                    if filedate > e.get_event_start() or filedate < e.get_event_stop():
                        success |= self.sync_file(f'{moth_mount_path}/{filename}', audio_path)
                        if success:
                            print(f'Transfer moved {filepath}')
                        else:
                            print(f'Tranfer issue found {filepath}')
                    else:
                        print(f'Transfer skipping {filepath}')
                except:
                    print(f'Transfer failed {filepath}')

        self.remove_files(moth_mount_path, pattern = '*.WAV', sudo = True)

        if success:
            logging.info("Transfer complete")
        else:
            logging.warning("Transfer failures occurred")
Esempio n. 2
0
    def sync_file(self, from_path:str, to_path:str):
        logging.info(f"File Transfer {from_path} to {to_path}")
        syncFilesCommand = f"rsync {from_path} {to_path}"
        e, success = output_shell(syncFilesCommand)

        if not success:
            logging.info(f"File Transfer failed: {e}")

        return success
Esempio n. 3
0
    def sync_files(self, from_path:str, to_path:str):
        logging.info("Transferring AudioMoth to Local")
        syncFilesCommand = "rsync -r {0}/ {1}".format(from_path, to_path)
        _, success = output_shell(syncFilesCommand)

        if success:
            logging.info("Transfer complete")

        return success
Esempio n. 4
0
    def remove_files(self, path:str, pattern:str = "*.WAV", sudo:bool = False):
        logging.info(f"Removing files from '{path}/{pattern}'")
        actor = 'sudo ' if sudo else ''
        removeMothFilesCommand = f"{actor}rm -f {path}/{pattern}"
        _, success = output_shell(removeMothFilesCommand)

        if success:
            logging.info("Removal complete")

        return success
Esempio n. 5
0
    def check_disk(self, report = True, display = True, path:str = "/"):
        total, used, free = shutil.disk_usage(path)

        if (report):
            logging.info(f"Disk at {path} (Total:{total} Used:{used} Free:{free})")

        if (display):
            gb = (2**20)
            print(f"Disk at {path} (Total:{total // gb} Used:{used // gb} Free:{free // gb} Avail:{(free * 100/total):.2f})")

        return total, used, free, (free/total) * 100
Esempio n. 6
0
    def remove_folder(self, path:str):
        logging.info("Remove Folder '{0}'".format(path))
        createFolderCommand = "rm -rf {0}".format(path)
        _, success = output_shell(createFolderCommand)

        if success:
            logging.info("Remove Folder successful")
        else:
            logging.info("Remove Folder unsuccessful")
Esempio n. 7
0
    def list_files(self, path:str, pattern: str = "*.WAV"):
        listMothFilesCommand = "ls -1Ap {0}/{1}".format(path, pattern)
        logging.info("Fetching files list in '{0}/{1}'".format(path, pattern))
        files, success = output_shell(listMothFilesCommand)
        fileList = [] if files is None else files.splitlines()

        if success and len(fileList) > 0:
            logging.info("Recordings count {0}".format(len(fileList)))
            logging.info(", ".join(fileList))
        else:
            logging.warning("No recordings found")
            return False

        return success, fileList
Esempio n. 8
0
#!/usr/bin/env python3

from crontab import CronTab, CronItem
from time import sleep
import sys

try:
    from lib.audiomoth import audiomoth
    from lib.config import Config
    from lib.log import logging
except:
    print('Failed to load dependencies')
    exit()

print('Flashing Moth', flush=True)
logging.info('Flashing Moth')

cfg = Config()
cfg.stop_required(True)

n = 120
while not cfg.is_stopped():
    sleep(1)
    n = n - 1
    print('s', flush=True)

    if (n < 0):
        print('Flashing failed waiting for Device to stop', flush=True)
        cfg.stop_clear()
        exit()