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}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)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.