Skip to content

Commit

Permalink
Fix problem with watchfile, when the file is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
0x9900 committed Nov 15, 2024
1 parent 694266f commit a10c58a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions eqsl/_eqsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def send_mail(qso, image):

msg.attach(MIMEText(template(data)))

logging.info('Sending qsl to: %s', qso.email)
with open(image, "rb") as fdi:
part = MIMEApplication(fdi.read(), Name=os.path.basename(image))
part['Content-Disposition'] = f'attachment; filename="{os.path.basename(image)}"'
Expand Down
9 changes: 7 additions & 2 deletions eqsl/sendcard.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
level=logging.INFO
)
wf_log = logging.getLogger('watchfiles.main')
wf_log.setLevel(logging.CRITICAL)
wf_log.setLevel(logging.INFO)

__version__ = version("e-qsl")

Expand All @@ -38,7 +38,7 @@ def send_cards(filename: Path, show_card: bool) -> None:
if not eqsl:
raise FileNotFoundError('eqsl not found')

args: list[str] = [eqsl, '-k', '-a', str(filename)]
args: list[str] = [eqsl, '-a', str(filename)]
if show_card:
args.append('-s')

Expand Down Expand Up @@ -84,8 +84,13 @@ def sendcard() -> None:
logging.info('Sendcards watching %s for %s', path, adif_file)
for changes in watch(path, watch_filter=watch_filter, recursive=False):
for change, filename in changes:
filename = Path(filename)
if change in (Change.added, Change.modified):
if not filename.exists():
continue
logging.info('Sending cards...')
send_cards(filename, opts.show)
logging.info('All the card sent. Back to watching %s', path)


def main():
Expand Down

0 comments on commit a10c58a

Please sign in to comment.