summaryrefslogtreecommitdiff
path: root/raphodo/generatename.py
diff options
context:
space:
mode:
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
+ )