summaryrefslogtreecommitdiff
path: root/raphodo/generatename.py
diff options
context:
space:
mode:
authorAntoine Beaupré <anarcat@debian.org>2018-03-14 12:24:17 -0400
committerAntoine Beaupré <anarcat@debian.org>2018-03-14 12:24:17 -0400
commit0a297829eaf3912c939e1b43a3ef6ddeb7607b38 (patch)
tree51733e0d6ffb00f0f7dfe01dccd48b2a598e5153 /raphodo/generatename.py
parent88c8bd4cd2ee4707f8a43be4d89c4e040dcced2f (diff)
New upstream version 0.9.9upstream/0.9.9
Diffstat (limited to 'raphodo/generatename.py')
-rw-r--r--raphodo/generatename.py91
1 files changed, 37 insertions, 54 deletions
diff --git a/raphodo/generatename.py b/raphodo/generatename.py
index bf28a7e..6d6f698 100644
--- a/raphodo/generatename.py
+++ b/raphodo/generatename.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-# Copyright (C) 2007-2016 Damon Lynch <damonlynch@gmail.com>
+# Copyright (C) 2007-2017 Damon Lynch <damonlynch@gmail.com>
# This file is part of Rapid Photo Downloader.
#
@@ -20,7 +20,7 @@
### USA
__author__ = 'Damon Lynch'
-__copyright__ = "Copyright 2007-2016, Damon Lynch"
+__copyright__ = "Copyright 2007-2017, Damon Lynch"
import re
from datetime import datetime, timedelta
@@ -35,13 +35,13 @@ locale.setlocale(locale.LC_ALL, '')
from gettext import gettext as _
from raphodo.preferences import DownloadsTodayTracker
-import raphodo.problemnotification as pn
from raphodo.problemnotification import (
RenamingProblems, FilenameNotFullyGeneratedProblem, make_href,
FolderNotFullyGeneratedProblemProblem, Problem
)
from raphodo.rpdfile import RPDFile, Photo, Video
from raphodo.storage import get_uri
+from raphodo.utilities import letters
from raphodo.generatenameconfig import *
@@ -352,22 +352,7 @@ class NameGeneration:
def _calculate_letter_sequence(self, sequence):
- def _letters(x):
- """
- Adapted from algorithm at
- http://en.wikipedia.org/wiki/Hexavigesimal
- """
- v = ''
- while x > 25:
- r = x % 26
- x = x / 26 - 1
- v = string.ascii_lowercase[r] + v
- v = string.ascii_lowercase[x] + v
-
- return v
-
-
- v = _letters(sequence)
+ v = letters(sequence)
if self.L2 == UPPERCASE:
v = v.upper()
@@ -380,22 +365,22 @@ class NameGeneration:
def _get_downloads_today(self):
return self._format_sequence_no(
- self.rpd_file.sequences.get_downloads_today(), self.L2
+ self.rpd_file.sequences.downloads_today, self.L2
)
def _get_session_sequence_no(self):
return self._format_sequence_no(
- self.rpd_file.sequences.get_session_sequence_no(), self.L2
+ self.rpd_file.sequences.session_sequence_no, self.L2
)
def _get_stored_sequence_no(self):
return self._format_sequence_no(
- self.rpd_file.sequences.get_stored_sequence_no(), self.L2
+ self.rpd_file.sequences.stored_sequence_no, self.L2
)
def _get_sequence_letter(self):
return self._calculate_letter_sequence(
- self.rpd_file.sequences.get_sequence_letter()
+ self.rpd_file.sequences.sequence_letter
)
def _get_sequences_component(self):
@@ -746,42 +731,37 @@ class Sequences:
"""
def __init__(self, downloads_today_tracker: DownloadsTodayTracker,
- stored_sequence_no: int):
- self.session_sequence_no = 0
- self.sequence_letter = -1
+ stored_sequence_no: int) -> None:
+ self._session_sequence_no = 0
+ self._sequence_letter = -1
self.downloads_today_tracker = downloads_today_tracker
- self.stored_sequence_no = stored_sequence_no
+ self._stored_sequence_no = stored_sequence_no
self.matched_sequences = None
+ self.use_matched_sequences = False
- def set_matched_sequence_value(self, matched_sequences: MatchedSequences) -> None:
- self.matched_sequences = matched_sequences
-
- def get_session_sequence_no(self) -> int:
- if self.matched_sequences is not None:
+ @property
+ def session_sequence_no(self) -> int:
+ if self.use_matched_sequences:
return self.matched_sequences.session_sequence_no
else:
- return self._get_session_sequence_no()
+ return self._session_sequence_no + 1
- def _get_session_sequence_no(self) -> int:
- return self.session_sequence_no + 1
-
- def get_sequence_letter(self) -> int:
- if self.matched_sequences is not None:
+ @property
+ def sequence_letter(self) -> int:
+ if self.use_matched_sequences:
return self.matched_sequences.sequence_letter
else:
- return self._get_sequence_letter()
-
- def _get_sequence_letter(self) -> int:
- return self.sequence_letter + 1
+ return self._sequence_letter + 1
def increment(self, uses_session_sequence_no, uses_sequence_letter) -> None:
if uses_session_sequence_no:
- self.session_sequence_no += 1
+ self._session_sequence_no += 1
if uses_sequence_letter:
- self.sequence_letter += 1
+ self._sequence_letter += 1
- def get_downloads_today(self) -> int:
- if self.matched_sequences is not None:
+ @property
+ def downloads_today(self) -> int:
+ if self.use_matched_sequences:
return self.matched_sequences.downloads_today
else:
return self._get_downloads_today()
@@ -793,18 +773,21 @@ class Sequences:
else:
return v + 1
- def get_stored_sequence_no(self) -> int:
- if self.matched_sequences is not None:
+ @property
+ def stored_sequence_no(self) -> int:
+ if self.use_matched_sequences:
return self.matched_sequences.stored_sequence_no
else:
- return self._get_stored_sequence_no()
+ return self._stored_sequence_no
- def _get_stored_sequence_no(self) -> int:
- return self.stored_sequence_no
+ @stored_sequence_no.setter
+ def stored_sequence_no(self, value: int) -> None:
+ self._stored_sequence_no = value
def create_matched_sequences(self) -> MatchedSequences:
return MatchedSequences(
- session_sequence_no=self._get_session_sequence_no(),
- sequence_letter=self._get_sequence_letter(),
+ session_sequence_no=self._session_sequence_no + 1,
+ sequence_letter=self._sequence_letter + 1,
downloads_today=self._get_downloads_today(),
- stored_sequence_no=self._get_stored_sequence_no())
+ stored_sequence_no=self._stored_sequence_no # no need for +1
+ )