[squeak-dev] The Trunk: Network-eem.249.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Oct 13 00:04:36 UTC 2021
Eliot Miranda uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-eem.249.mcz
==================== Summary ====================
Name: Network-eem.249
Author: eem
Time: 12 October 2021, 5:04:34.016607 pm
UUID: e005ce57-6681-403f-8cea-862ea013cd14
Ancestors: Network-ul.248
Extend HTTPServerDirectory so that it can parse XML descriptions as per e.g. http://files.squeak.org/trunk/. This works, but could really do with a review from someone intimately familiar with ServerDirectory and subclasses.
Hence the following gets the latest trunk images and unpacks them:
| entries |
entries := (HTTPServerDirectory new type: #http)
altUrl: 'http://files.squeak.org/trunk/';
entries.
#('32bit' '64bit') do:
[:bitness| | latest |
latest := (entries select: [:entry| entry name includesSubstring: bitness])
inject: entries first
into: [:best :each| | vnb vne |
vnb := (best name subStrings: '-') second asInteger.
vne := (each name subStrings: '-') second asInteger.
vnb > vne
ifTrue: [best]
ifFalse: [each]].
Cursor write showWhile:
[(Cursor read showWhile:
[ZipArchive new readFrom: (((HTTPServerDirectory new type: #http)
altUrl: (latest containingDirectory altUrl, latest name);
entries) detect: [:entry| entry name endsWith: 'bit.zip']) readStream])
extractAllTo: FileDirectory default
informing: nil
overwrite: true]]
=============== Diff against Network-ul.248 ===============
Item was changed:
----- Method: HTTPServerDirectory>>entries (in category 'file directory') -----
entries
| answer ftpEntries |
answer := HTTPSocket httpGetDocument: self dirListUrl.
answer isString
ifTrue: [^self error: 'Listing failed: ' , answer]
ifFalse: [answer := answer content].
+ answer first = $< ifTrue:
+ [(answer first: 5) = '<?xml' ifTrue:
+ [(Smalltalk classNamed: #XMLDOMParser) ifNotNil:
+ [^self parseFTPEntriesFromXML: (XMLDOMParser parseDocumentFrom: answer readStream useNamespaces: true)]].
+ self error: 'Listing failed: ' , answer].
- answer first = $<
- ifTrue: [self error: 'Listing failed: ' , answer].
ftpEntries := answer lines.
^ ftpEntries
collect:[:ftpEntry | self class parseFTPEntry: ftpEntry]
thenSelect: [:entry | entry notNil]!
Item was added:
+ ----- Method: HTTPServerDirectory>>fileSizeFromString: (in category 'misc') -----
+ fileSizeFromString: aString
+ | size |
+ size := aString asNumber.
+ ('KMGTP' indexOf: aString last asUppercase ifAbsent: nil) ifNotNil:
+ [:index| size := size * (2 raisedTo: index * 10)]. "1k = 2^10, etc..."
+ ^size asInteger!
Item was added:
+ ----- Method: HTTPServerDirectory>>parseFTPEntriesFromXML: (in category 'misc') -----
+ parseFTPEntriesFromXML: anXMLDocument
+ | entries |
+ entries := OrderedCollection new.
+ anXMLDocument
+ tagsNamed: #tr
+ ifReceiverDoAndRecurse:
+ [:node| | ec |
+ ((ec := node elementsAndContents) size = 4
+ and: [((ec := ec asArray) allSatisfy: [:n| n isTag])
+ and: [((ec collect: [:n| n attributeAt: 'class']) sameElements: #('n' 'm' 's' 't'))]]) ifTrue:
+ [[:n :m :s :t| | modificationString nameString |
+ (n isTag
+ and: [(modificationString := m string) size > 12 "YYYYMMDDHHSS"
+ and: [modificationString first isDigit]]) ifTrue:
+ [nameString := n attributeAt: 'href'.
+ entries addLast:
+ (t string = 'Directory' "is-a-directory flag"
+ ifTrue:
+ [DirectoryEntryDirectory
+ directory: self
+ name: nameString "file name"
+ creationTime: nil
+ modificationTime: modificationString asDateAndTime "modification time"
+ fileSize: nil]
+ ifFalse:
+ [DirectoryEntryFile
+ directory: self
+ name: nameString "file name"
+ creationTime: nil
+ modificationTime: modificationString asDateAndTime "modification time"
+ fileSize: (self fileSizeFromString: s string)])]] valueWithArguments: (ec collect: [:element| element elementsAndContents first])]].
+ ^entries!
More information about the Squeak-dev
mailing list
|