From a7e72b5d9d4efd6895a673d7f534ae2fef8145a8 Mon Sep 17 00:00:00 2001 From: Offray Luna Date: Thu, 7 Dec 2017 11:21:36 +0000 Subject: [PATCH] Improved support for downloading files and creation of local subdirectories for them. --- .../GrafoscopioDocumentation.class.st | 11 ++++----- .../GrafoscopioUtils.class.st | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/repository/Grafoscopio-Utils/GrafoscopioDocumentation.class.st b/repository/Grafoscopio-Utils/GrafoscopioDocumentation.class.st index 3a55990..e8aff71 100644 --- a/repository/Grafoscopio-Utils/GrafoscopioDocumentation.class.st +++ b/repository/Grafoscopio-Utils/GrafoscopioDocumentation.class.st @@ -71,17 +71,14 @@ GrafoscopioDocumentation >> documents: anObject [ { #category : #updating } GrafoscopioDocumentation >> download: fileNameWithRelativePath [ - | fileName relativePathFolders newPath parentFolder | + | fileName parentFolder | fileName := (fileNameWithRelativePath splitOn: $/) last. - relativePathFolders := (fileNameWithRelativePath splitOn: $/) allButLast. - newPath := self localPlace path. - relativePathFolders do: [ :folder | newPath := newPath / folder ]. - parentFolder := newPath asFileReference. - parentFolder exists ifFalse: [ parentFolder ensureCreateDirectory ]. + parentFolder := GrafoscopioUtils + ensureCreateDirectory: fileNameWithRelativePath into: self localPlace. GrafoscopioUtils downloadingFrom: self repository remote asString, '/doc/tip/', fileNameWithRelativePath withMessage: 'Downloading ', fileName - into: parentFolder + into: parentFolder ] { #category : #updating } diff --git a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st index b85f580..b88e6c1 100644 --- a/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st +++ b/repository/Grafoscopio-Utils/GrafoscopioUtils.class.st @@ -13,6 +13,17 @@ GrafoscopioUtils class >> checksumFor: aFileReference [ ^ (SHA1 new hashMessage: aFileReference binaryReadStream contents) hex. ] +{ #category : #updating } +GrafoscopioUtils class >> download: fileNameWithRelativePath from: urlString into: aFolder [ + | fileName parentFolder | + fileName := (fileNameWithRelativePath splitOn: $/) last. + parentFolder := self ensureCreateDirectory: fileNameWithRelativePath into: aFolder. + self + downloadingFrom: urlString, fileNameWithRelativePath + withMessage: 'Downloading ', fileName + into: parentFolder +] + { #category : #'graphical interface' } GrafoscopioUtils class >> downloadingFrom: downloadUrl withMessage: aString into: location [ | fileName | @@ -33,6 +44,18 @@ GrafoscopioUtils class >> downloadingFrom: downloadUrl withMessage: aString into ] asJob run. ] +{ #category : #utilities } +GrafoscopioUtils class >> ensureCreateDirectory: fileNameWithRelativePath into: aFolder [ + | relativePathFolders parentFolder newPath | + relativePathFolders := (fileNameWithRelativePath splitOn: $/) allButLast. + newPath := aFolder path. + relativePathFolders do: [ :folder | newPath := newPath / folder ]. + parentFolder := newPath asFileReference. + parentFolder ensureCreateDirectory. + ^ parentFolder + +] + { #category : #'graphical interface' } GrafoscopioUtils class >> getContentsFrom: url withMessage: aString [ | client |