Skip to content

Commit

Permalink
*IP/SQ: Add logic for Do Not Download groups. Needs tests, release no…
Browse files Browse the repository at this point in the history
…tes, and docs.
  • Loading branch information
davidfstr committed Jan 17, 2024
1 parent 68edeb0 commit 5094c84
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
21 changes: 17 additions & 4 deletions src/crystal/browser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,29 @@ def _on_new_group(self, event: wx.CommandEvent) -> None:
pass

@fg_affinity
def _on_new_group_dialog_ok(self, name: str, url_pattern: str, source: ResourceGroupSource) -> None:
def _on_new_group_dialog_ok(self,
name: str,
url_pattern: str,
source: ResourceGroupSource,
do_not_download: bool,
) -> None:
# TODO: Validate user input:
# * Is url_pattern empty?
# * Is url_pattern already taken?
ResourceGroup(self.project, name, url_pattern, source)
rg = ResourceGroup(self.project, name, url_pattern, source)
rg.do_not_download = do_not_download

@fg_affinity
def _on_edit_group_dialog_ok(self, rg: ResourceGroup, name: str, url_pattern: str, source: ResourceGroupSource) -> None:
def _on_edit_group_dialog_ok(self,
rg: ResourceGroup,
name: str,
url_pattern: str,
source: ResourceGroupSource,
do_not_download: bool,
) -> None:
if url_pattern != rg.url_pattern:
raise ValueError()
(rg.name, rg.source) = (name, source)
(rg.name, rg.source, rg.do_not_download) = (name, source, do_not_download)

# TODO: This update should happen in response to an event
# fired by the entity itself.
Expand Down Expand Up @@ -555,6 +567,7 @@ def _on_edit_entity(self, event) -> None:
initial_url_pattern=rg.url_pattern,
initial_source=rg.source,
initial_name=rg.name,
initial_do_not_download=rg.do_not_download,
is_edit=True)
except CancelLoadUrls:
pass
Expand Down
35 changes: 25 additions & 10 deletions src/crystal/browser/new_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ class NewGroupDialog:

def __init__(self,
parent: wx.Window,
on_finish: Callable[[str, str, ResourceGroupSource], None],
on_finish: Callable[[str, str, ResourceGroupSource, bool], None],
project: Project,
saving_source_would_create_cycle_func: Callable[[ResourceGroupSource], bool],
initial_url_pattern: str='',
initial_source: ResourceGroupSource=None,
initial_name: str='',
initial_do_not_download: bool=False,
is_edit: bool=False,
) -> None:
"""
Expand Down Expand Up @@ -84,7 +85,7 @@ def __init__(self,
flag=wx.EXPAND|preview_box_flags,
border=preview_box_border)
content_sizer.Add(
self._create_advanced_options(dialog),
self._create_advanced_options(dialog, initial_do_not_download),
flag=wx.EXPAND|wx.TOP,
border=10)

Expand Down Expand Up @@ -226,22 +227,35 @@ def _create_preview_box_content(self, parent: wx.Window) -> wx.Sizer:

return content_sizer

def _create_advanced_options(self, parent: wx.Window) -> wx.Sizer:
def _create_advanced_options(self, parent: wx.Window, *args, **kwargs) -> wx.Sizer:
options_sizer = wx.StaticBoxSizer(wx.VERTICAL, parent, label='Advanced Options')
options_sizer.Add(
wrap_static_box_sizer_child(
self._create_advanced_options_content(
options_sizer.GetStaticBox())),
options_sizer.GetStaticBox(),
*args, **kwargs)),
flag=wx.EXPAND)
return options_sizer

def _create_advanced_options_content(self, parent: wx.Window) -> wx.Sizer:
def _create_advanced_options_content(self,
parent: wx.Window,
initial_do_not_download: bool,
) -> wx.Sizer:
options_sizer = wx.BoxSizer(wx.VERTICAL)

options_sizer.Add(
wx.StaticText(parent, label='These options reset when Crystal quits.'),
)

self.do_not_download_checkbox = wx.CheckBox(
parent, label='Do not download members',
parent, label='Do not download members when embedded',
name='cr-new-group-dialog__do-not-download-checkbox')
options_sizer.Add(self.do_not_download_checkbox)
self.do_not_download_checkbox.Value = initial_do_not_download
options_sizer.Add(
self.do_not_download_checkbox,
flag=wx.TOP,
border=8,
)
options_sizer.AddSpacer(_FORM_ROW_SPACING)

sequential_row = wx.BoxSizer(wx.HORIZONTAL)
Expand Down Expand Up @@ -392,8 +406,8 @@ def _on_close(self, event: wx.CloseEvent) -> None:
self._on_cancel(event)

def _on_ok(self, event: wx.CommandEvent) -> None:
name = self.name_field.GetValue()
url_pattern = self.pattern_field.GetValue()
name = self.name_field.Value
url_pattern = self.pattern_field.Value
source = self.source_choice_box.GetClientData(
self.source_choice_box.GetSelection())
if self._saving_source_would_create_cycle_func(source):
Expand All @@ -408,7 +422,8 @@ def _on_ok(self, event: wx.CommandEvent) -> None:
choice = ShowModal(dialog)
assert wx.ID_OK == choice
return
self._on_finish(name, url_pattern, source)
do_not_download = self.do_not_download_checkbox.Value
self._on_finish(name, url_pattern, source, do_not_download)

self.dialog.Destroy()

Expand Down
1 change: 1 addition & 0 deletions src/crystal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3152,6 +3152,7 @@ def __init__(self,
self.url_pattern = url_pattern
self._url_pattern_re = ResourceGroup.create_re_for_url_pattern(url_pattern)
self._source = None # type: Union[ResourceGroupSource, EllipsisType]
self.do_not_download = False

# Calculate members on demand rather than up front
self._members = None # type: Optional[List[Resource]]
Expand Down
3 changes: 2 additions & 1 deletion src/crystal/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ def _find_root_resource_matching_archive_url(self, archive_url: str) -> Optional
return None

def _find_group_matching_archive_url(self, archive_url: str) -> Optional[ResourceGroup]:
# ...excluding "do not download" groups
for rg in self.project.resource_groups:
if rg.contains_url(archive_url):
if rg.contains_url(archive_url) and not rg.do_not_download:
return rg
return None

Expand Down
4 changes: 3 additions & 1 deletion src/crystal/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ def fg_task() -> List[Resource]:
link_urls_seen = set()
base_url = self._resource.url # cache
project = self._resource.project # cache
dnd_groups = [g for g in project.resource_groups if g.do_not_download] # cache
for link in links:
if not link.embedded:
continue
Expand All @@ -902,7 +903,8 @@ def fg_task() -> List[Resource]:
# by ParseResourceRevisionLinks and being
# accessed here.
link_resource = Resource(project, link_url)
embedded_resources.append(link_resource)
if not any([g.contains_url(link_resource.url) for g in dnd_groups]):
embedded_resources.append(link_resource)
return embedded_resources
embedded_resources = fg_call_and_wait(fg_task)

Expand Down

0 comments on commit 5094c84

Please sign in to comment.