-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save synced filenams and skip sync next times #454
Changes from 6 commits
4561c60
a6be158
d0ea0ff
1128a62
cd3bcf9
eedcd99
ebae905
771ef56
55f48cc
a00ede4
96c440a
87e7d06
08e3877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ | |
from .db import Activity, init_db, update_or_create_activity | ||
|
||
|
||
sys.path.append("..") | ||
agassiyzh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. from utils import save_synced_data_file_list |
||
|
||
|
||
IGNORE_BEFORE_SAVING = os.getenv("IGNORE_BEFORE_SAVING", False) | ||
|
||
|
||
|
@@ -78,25 +82,33 @@ def sync_from_data_dir(self, data_dir, file_suffix="gpx"): | |
if not tracks: | ||
print("No tracks found.") | ||
return | ||
|
||
synced_files = [] | ||
|
||
for t in tracks: | ||
created = update_or_create_activity(self.session, t.to_namedtuple()) | ||
if created: | ||
sys.stdout.write("+") | ||
synced_files.extend(t.file_names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the record already synced before this patch, would the |
||
else: | ||
sys.stdout.write(".") | ||
sys.stdout.flush() | ||
|
||
utils.save_synced_data_file_list(data_dir, synced_files) | ||
|
||
self.session.commit() | ||
|
||
def sync_from_app(self, app_tracks): | ||
if not app_tracks: | ||
print("No tracks found.") | ||
return | ||
print("Syncing tracks '+' means new track '.' means update tracks") | ||
synced_files = [] | ||
for t in app_tracks: | ||
created = update_or_create_activity(self.session, t) | ||
if created: | ||
sys.stdout.write("+") | ||
synced_files.extend(t.file_names) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
else: | ||
sys.stdout.write(".") | ||
sys.stdout.flush() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
from .track import Track | ||
from .year_range import YearRange | ||
|
||
import utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
|
@@ -167,12 +169,15 @@ def _load_data_tracks(file_names, load_func=load_gpx_file): | |
|
||
@staticmethod | ||
def _list_data_files(data_dir, file_suffix): | ||
synced_files = utils.load_synced_file_list(data_dir) | ||
data_dir = os.path.abspath(data_dir) | ||
if not os.path.isdir(data_dir): | ||
raise ParameterError(f"Not a directory: {data_dir}") | ||
for name in os.listdir(data_dir): | ||
if name.startswith("."): | ||
continue | ||
if name in synced_files: | ||
continue | ||
path_name = os.path.join(data_dir, name) | ||
if name.endswith(f".{file_suffix}") and os.path.isfile(path_name): | ||
yield path_name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's convenient to set to var to abs path with the name
SYNCED_FILE
, just like the line above. Then you can use it anywhere with ease.