From 90dd21b270c1a98e45c4692b129f5dc103f8a6df Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Tue, 15 Apr 2014 10:43:36 +0400 Subject: [PATCH] Raw (machine-readable) format for aptly mirror/repo/snapshot list. #27 --- cmd/mirror_list.go | 43 ++++++++++++++------- cmd/repo_list.go | 44 +++++++++++++++------- cmd/snapshot_list.go | 43 ++++++++++++++------- system/t04_mirror/ListMirror3Test_gold | 12 ++++++ system/t04_mirror/ListMirror4Test_gold | 0 system/t04_mirror/list.py | 15 ++++++++ system/t05_snapshot/ListSnapshot3Test_gold | 5 +++ system/t05_snapshot/ListSnapshot4Test_gold | 0 system/t05_snapshot/list.py | 24 ++++++++++++ system/t09_repo/ListRepo2Test_gold | 2 +- system/t09_repo/ListRepo3Test_gold | 0 system/t09_repo/ListRepo4Test_gold | 3 ++ system/t09_repo/list.py | 19 ++++++++++ 13 files changed, 167 insertions(+), 43 deletions(-) create mode 100644 system/t04_mirror/ListMirror3Test_gold create mode 100644 system/t04_mirror/ListMirror4Test_gold create mode 100644 system/t05_snapshot/ListSnapshot3Test_gold create mode 100644 system/t05_snapshot/ListSnapshot4Test_gold create mode 100644 system/t09_repo/ListRepo3Test_gold create mode 100644 system/t09_repo/ListRepo4Test_gold diff --git a/cmd/mirror_list.go b/cmd/mirror_list.go index aa19a566..11d9caba 100644 --- a/cmd/mirror_list.go +++ b/cmd/mirror_list.go @@ -14,24 +14,37 @@ func aptlyMirrorList(cmd *commander.Command, args []string) error { return err } - if context.CollectionFactory().RemoteRepoCollection().Len() > 0 { - fmt.Printf("List of mirrors:\n") - repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len()) - i := 0 - context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error { + raw := cmd.Flag.Lookup("raw").Value.Get().(bool) + + repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len()) + i := 0 + context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error { + if raw { + repos[i] = repo.Name + } else { repos[i] = repo.String() - i++ - return nil - }) - - sort.Strings(repos) - for _, repo := range repos { - fmt.Printf(" * %s\n", repo) } + i++ + return nil + }) - fmt.Printf("\nTo get more information about mirror, run `aptly mirror show `.\n") + sort.Strings(repos) + + if raw { + for _, repo := range repos { + fmt.Printf("%s\n", repo) + } } else { - fmt.Printf("No mirrors found, create one with `aptly mirror create ...`.\n") + if len(repos) > 0 { + fmt.Printf("List of mirrors:\n") + for _, repo := range repos { + fmt.Printf(" * %s\n", repo) + } + + fmt.Printf("\nTo get more information about mirror, run `aptly mirror show `.\n") + } else { + fmt.Printf("No mirrors found, create one with `aptly mirror create ...`.\n") + } } return err } @@ -50,5 +63,7 @@ Example: `, } + cmd.Flag.Bool("raw", false, "display list in machine-readable format") + return cmd } diff --git a/cmd/repo_list.go b/cmd/repo_list.go index c1577b35..04b4623c 100644 --- a/cmd/repo_list.go +++ b/cmd/repo_list.go @@ -14,30 +14,44 @@ func aptlyRepoList(cmd *commander.Command, args []string) error { return err } - if context.CollectionFactory().LocalRepoCollection().Len() > 0 { - fmt.Printf("List of mirrors:\n") - repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len()) - i := 0 - context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error { + raw := cmd.Flag.Lookup("raw").Value.Get().(bool) + + repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len()) + i := 0 + context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error { + if raw { + repos[i] = repo.Name + } else { err := context.CollectionFactory().LocalRepoCollection().LoadComplete(repo) if err != nil { return err } repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages()) - i++ - return nil - }) - - sort.Strings(repos) - for _, repo := range repos { - fmt.Println(repo) } + i++ + return nil + }) - fmt.Printf("\nTo get more information about local repository, run `aptly repo show `.\n") + sort.Strings(repos) + + if raw { + for _, repo := range repos { + fmt.Printf("%s\n", repo) + } } else { - fmt.Printf("No local repositories found, create one with `aptly repo create ...`.\n") + if len(repos) > 0 { + fmt.Printf("List of local repos:\n") + for _, repo := range repos { + fmt.Println(repo) + } + + fmt.Printf("\nTo get more information about local repository, run `aptly repo show `.\n") + } else { + fmt.Printf("No local repositories found, create one with `aptly repo create ...`.\n") + } } + return err } @@ -55,5 +69,7 @@ Example: `, } + cmd.Flag.Bool("raw", false, "display list in machine-readable format") + return cmd } diff --git a/cmd/snapshot_list.go b/cmd/snapshot_list.go index 37ee6ab1..39c8b1d2 100644 --- a/cmd/snapshot_list.go +++ b/cmd/snapshot_list.go @@ -14,26 +14,39 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error { return err } - if context.CollectionFactory().SnapshotCollection().Len() > 0 { - fmt.Printf("List of snapshots:\n") + raw := cmd.Flag.Lookup("raw").Value.Get().(bool) - snapshots := make([]string, context.CollectionFactory().SnapshotCollection().Len()) + snapshots := make([]string, context.CollectionFactory().SnapshotCollection().Len()) - i := 0 - context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error { + i := 0 + context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error { + if raw { + snapshots[i] = snapshot.Name + } else { snapshots[i] = snapshot.String() - i++ - return nil - }) - - sort.Strings(snapshots) - for _, snapshot := range snapshots { - fmt.Printf(" * %s\n", snapshot) } + i++ + return nil + }) - fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show `.\n") + sort.Strings(snapshots) + + if raw { + for _, snapshot := range snapshots { + fmt.Printf("%s\n", snapshot) + } } else { - fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n") + if len(snapshots) > 0 { + fmt.Printf("List of snapshots:\n") + + for _, snapshot := range snapshots { + fmt.Printf(" * %s\n", snapshot) + } + + fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show `.\n") + } else { + fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n") + } } return err @@ -53,5 +66,7 @@ Example: `, } + cmd.Flag.Bool("raw", false, "display list in machine-readable format") + return cmd } diff --git a/system/t04_mirror/ListMirror3Test_gold b/system/t04_mirror/ListMirror3Test_gold new file mode 100644 index 00000000..3aee199b --- /dev/null +++ b/system/t04_mirror/ListMirror3Test_gold @@ -0,0 +1,12 @@ +gnuplot-maverick +gnuplot-maverick-src +wheezy-backports +wheezy-backports-src +wheezy-contrib +wheezy-contrib-src +wheezy-main +wheezy-main-src +wheezy-non-free +wheezy-non-free-src +wheezy-updates +wheezy-updates-src diff --git a/system/t04_mirror/ListMirror4Test_gold b/system/t04_mirror/ListMirror4Test_gold new file mode 100644 index 00000000..e69de29b diff --git a/system/t04_mirror/list.py b/system/t04_mirror/list.py index 31bf36f5..f97759f3 100644 --- a/system/t04_mirror/list.py +++ b/system/t04_mirror/list.py @@ -19,3 +19,18 @@ class ListMirror2Test(BaseTest): list mirrors: empty list """ runCmd = "aptly mirror list" + + +class ListMirror3Test(BaseTest): + """ + list mirrors: raw list + """ + fixtureDB = True + runCmd = "aptly -raw mirror list" + + +class ListMirror4Test(BaseTest): + """ + list mirrors: raw empty list + """ + runCmd = "aptly -raw mirror list" diff --git a/system/t05_snapshot/ListSnapshot3Test_gold b/system/t05_snapshot/ListSnapshot3Test_gold new file mode 100644 index 00000000..1d160505 --- /dev/null +++ b/system/t05_snapshot/ListSnapshot3Test_gold @@ -0,0 +1,5 @@ +snap1 +snap2 +snap3 +snap4 +snap5 diff --git a/system/t05_snapshot/ListSnapshot4Test_gold b/system/t05_snapshot/ListSnapshot4Test_gold new file mode 100644 index 00000000..e69de29b diff --git a/system/t05_snapshot/list.py b/system/t05_snapshot/list.py index 71f754fe..8d135d15 100644 --- a/system/t05_snapshot/list.py +++ b/system/t05_snapshot/list.py @@ -23,3 +23,27 @@ class ListSnapshot2Test(BaseTest): list snapshots: empty list """ runCmd = "aptly snapshot list" + + +class ListSnapshot3Test(BaseTest): + """ + list snapshots: raw regular list + """ + fixtureDB = True + fixtureCmds = [ + "aptly snapshot create snap1 from mirror wheezy-main", + "aptly snapshot create snap2 from mirror wheezy-contrib", + "aptly snapshot merge snap3 snap1 snap2", + "aptly snapshot pull snap1 snap2 snap4 mame unrar", + "aptly repo create local-repo", + "aptly repo add local-repo ${files}", + "aptly snapshot create snap5 from repo local-repo", + ] + runCmd = "aptly -raw snapshot list" + + +class ListSnapshot4Test(BaseTest): + """ + list snapshots: raw empty list + """ + runCmd = "aptly snapshot -raw list" diff --git a/system/t09_repo/ListRepo2Test_gold b/system/t09_repo/ListRepo2Test_gold index fba1c276..9d8914c2 100644 --- a/system/t09_repo/ListRepo2Test_gold +++ b/system/t09_repo/ListRepo2Test_gold @@ -1,4 +1,4 @@ -List of mirrors: +List of local repos: * [repo1] (packages: 0) * [repo2]: Cool2 (packages: 0) * [repo3]: Cool3 (packages: 0) diff --git a/system/t09_repo/ListRepo3Test_gold b/system/t09_repo/ListRepo3Test_gold new file mode 100644 index 00000000..e69de29b diff --git a/system/t09_repo/ListRepo4Test_gold b/system/t09_repo/ListRepo4Test_gold new file mode 100644 index 00000000..3fc9dcf4 --- /dev/null +++ b/system/t09_repo/ListRepo4Test_gold @@ -0,0 +1,3 @@ +repo1 +repo2 +repo3 diff --git a/system/t09_repo/list.py b/system/t09_repo/list.py index 11861cfc..9be862a2 100644 --- a/system/t09_repo/list.py +++ b/system/t09_repo/list.py @@ -18,3 +18,22 @@ class ListRepo2Test(BaseTest): "aptly repo create repo1", ] runCmd = "aptly repo list" + + +class ListRepo3Test(BaseTest): + """ + list local repos: raw no repos + """ + runCmd = "aptly -raw repo list" + + +class ListRepo4Test(BaseTest): + """ + list local repo: raw normal + """ + fixtureCmds = [ + "aptly repo create -comment=Cool3 repo3", + "aptly repo create -comment=Cool2 repo2", + "aptly repo create repo1", + ] + runCmd = "aptly repo list -raw"