Skip to main content
Engineering LibreTexts

7.5: Some Useful Scripts

  • Page ID
    43831
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Gofer offers a nice facility to gather all the packages together in a given repository via the message allResolved.

    Script \(\PageIndex{1}\) (Pharo): Getting the number of packages in a repository.

    (Gofer new
        smalltalkhubUser: 'Pharo' project: 'NativeBoost';
        allResolved) size
    

    The following script gathers the package versions by packages and returns a dictionary.

    Script \(\PageIndex{2}\) (Pharo): Grouping version by package names.

    ((Gofer new
        smalltalkhubUser: 'Pharo' project: 'NativeBoost';
        allResolved)
        groupedBy: [ :each | each packageName])
    

    Script \(\PageIndex{3}\) (Pharo): Getting the package list for the Kozen project hosted on SS3.

    ((Gofer new
        squeaksource3: 'Kozen';
        allResolved)
        groupedBy: [ :each | each packageName]) keys
    

    Fetching packages

    Here is a script to fetch all the packages of a given repository. It is useful for grabbing your files and having a version locally.

    Script \(\PageIndex{4}\) (Pharo): Fetching all the packages of a repository.

    | go |
    go := Gofer new squeaksource3: 'Pharo20'.
    go allResolved
        do: [ :each |
            self crLog: each packageName.
            go package: each packageName;
                fetch]
    

    Script \(\PageIndex{5}\) (Pharo): Fetching all the refactoring packages from the Pharo2.0 repository.

    | go |
    go := Gofer new.
    go squeaksource3: 'Pharo20'.
    (go allResolved select: [ :each | 'Refactoring*' match: each packageName])
        do: [ :pack |
            self crLog: pack packageName.
            go package: pack packageName; fetch]
    

    Publishing local files

    The following script publishes files from your local cache to a given repository.

    Script \(\PageIndex{6}\) (Pharo): How to publish package files to a new repository using Pharo 1.4.

    | go |
    go := Gofer new.
    go repository: (MCHttpRepository
        location: 'http://ss3.gemtalksystems.com/ss/Pharo14'
        user: 'pharoUser'
        password: 'pharoPwd').
    
    ((FileSystem workingDirectory / 'package-cache')
        allEntries
            select: [ :each | '*.mcz' match: each])
                    do: [ :f | go version: ('.' join: (f findTokens: $.) allButLast); push]
    

    The following script uses the new filesystem library, we also show how we can get the package name and not the versions. The script also pays attention to only publish mcz files. It can be extended to publish selectively specific packages.

    Script \(\PageIndex{7}\) (Pharo): How to publish package files to a new repository using Pharo20

    | go |
    go := Gofer new.
    go repository: (MCHttpRepository
        location: 'http://ss3.gemtalksystems.com/ss/rb-pharo'
        user: 'pharoUser'
        password: 'pharoPwd').
    
    (((FileSystem disk workingDirectory / 'package-cache')
        allFiles select: [:each | '*.mcz' match: each basename])
            groupedBy: [:each | (each base copyUpToLast: $-) ])
                keys do: [:name | go package: name; push]
    

    Script \(\PageIndex{8}\) (Pharo): How to publish Fame to the Moose Team on SmalltalkHub

    |go repo|
    repo := MCSmalltalkhubRepository
        owner: 'Moose'
        project: 'Fame'
        user: 'pharoUser'
        password: 'pharoPwd'.
    
    go := Gofer new.
    go repository: repo.
    (((FileSystem disk workingDirectory / 'package-cache')
        allFiles select: [:each | '*Fame*.mcz' match: each basename])
            groupedBy: [:each | (each base copyUpToLast: $-) ]) keys
                do: [:name | go package: name; push]
    

    All in one page

    Since we love simple scripts where we do not have to think too much, here is a full version to migrate between Monticello repositories.

    Script \(\PageIndex{9}\) (Pharo): Script to synchronize from one Monticello repository to another

    | source goferSource destination goferDestination files destinationFiles |
    
    source := MCHttpRepository
        location: 'http://www.squeaksource.com/MyProject'.
    destination := MCSmalltalkhubRepository
        owner: 'TheOwner'
        project: 'YourPackage'
        user: 'YourName'
        password: ''.
    
    goferSource := Gofer new repository: source.
    goferDestination := Gofer new repository: destination.
    
    files := source allVersionNames.
    "select the relevant mcz packages"
    goferSource allResolved
        select: [ :resolved | files anySatisfy: [ :each | resolved name = each ] ]
        thenDo: [ :each | goferSource package: each packageName ].
    "download all mcz on your computer"
    goferSource fetch.
    
    "check what files are already at destination"
    destinationFiles := destination allVersionNames.
    "select only the mcz that are not yet at destination"
    files
        reject: [ :file | destinationFiles includes: file ]
        thenDo: [ :file | goferDestination version: file ].
    "send everything to SmalltalkHub"
    goferDestination push.
    
    "check if we have exactly the same files at source and destination"
    destination allVersionNames sorted = files sorted.
    

    This page titled 7.5: Some Useful Scripts is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Alexandre Bergel, Damien Cassou, Stéphane Ducasse, Jannik Laval (Square Bracket Associates) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.