Skip to content

Commit

Permalink
Add ressources downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyan11 committed Oct 25, 2023
1 parent cfaaace commit 3183917
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ BaselineOfMoleculeGeographicalPositionExample >> loadPyramid: spec [

{ #category : #'load scripts' }
BaselineOfMoleculeGeographicalPositionExample >> postload: loader package: packageSpec [
"do nothing"

| molGeoDownloadedRessource |

molGeoDownloadedRessource := #MolGeoDownloadedRessource asClassInEnvironment: self class environment.

molGeoDownloadedRessource ensureAllDownloaded

]

{ #category : #'load scripts' }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Class {
#name : #MolGeoDownloadedRessource,
#superclass : #Object,
#instVars : [
'downloadDirectory'
],
#category : #'Molecule-Geographical-Position-Example'
}

{ #category : #'as yet unclassified' }
MolGeoDownloadedRessource class >> ensureAllDownloaded [

<script: 'self ensureAllDownloaded'>
self allSubclassesDo: [ :each |
each new
downloadDirectory: self ressourcesDirectory;
ensureDownloaded ]
]

{ #category : #'as yet unclassified' }
MolGeoDownloadedRessource class >> ressourcesDirectory [
| reference |
reference := FileLocator imageDirectory asFileReference / 'ressources'.
(reference exists and: [ reference isDirectory ]) ifTrue: [ ^ reference ].
(reference exists and: [ reference isDirectory not ]) ifTrue: [ Error signal: 'ressources directory is not a directory.' ].
DiskStore current createDirectory: reference asPath.
^ reference
]

{ #category : #testing }
MolGeoDownloadedRessource >> baseUrl [

^ self subclassResponsibility
]

{ #category : #testing }
MolGeoDownloadedRessource >> download [

('Downloading {1}...' format: { self fileName }) traceCr.

[
ZnClient new
url: self baseUrl , self fileName;
numberOfRetries: 5;
timeout: 100;
logToTranscript;
downloadTo: self downloadDirectory ensureCreateDirectory;
yourself.

'
Download finished - ' trace ] timeToRun traceCr
]

{ #category : #testing }
MolGeoDownloadedRessource >> downloadDirectory [

^ downloadDirectory
]

{ #category : #testing }
MolGeoDownloadedRessource >> downloadDirectory: aFileReference [

downloadDirectory := aFileReference
]

{ #category : #testing }
MolGeoDownloadedRessource >> ensureDownloaded [

self isDownloaded ifFalse: [ self download ]
]

{ #category : #testing }
MolGeoDownloadedRessource >> fileName [

^ self subclassResponsibility
]

{ #category : #testing }
MolGeoDownloadedRessource >> fileReference [

^ self downloadDirectory / self fileName
]

{ #category : #testing }
MolGeoDownloadedRessource >> isDownloaded [

^ self fileReference exists
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Class {
#name : #MolGeoMapDownloaded,
#superclass : #MolGeoDownloadedRessource,
#category : #'Molecule-Geographical-Position-Example'
}

{ #category : #testing }
MolGeoMapDownloaded >> baseUrl [

^ self subclassResponsibility
]

{ #category : #testing }
MolGeoMapDownloaded >> fileName [

^ self subclassResponsibility
]

0 comments on commit 3183917

Please sign in to comment.