├── .gitattributes ├── .gitignore ├── .travis.yml ├── ADVANCED.md ├── Makefile ├── README.md ├── RunSettings.go ├── StringSet.go ├── TemplateRegistry.go ├── TemplatedFile.go ├── TemplatedProject.go ├── archive.go ├── autocomplete └── wisk ├── docs └── wisk.7 ├── fileutil.go ├── main.go ├── postGenerateScript.go └── samples ├── helloworld_chef ├── README.md ├── attributes │ └── default.rb ├── metadata.rb └── recipes │ └── default.rb ├── helloworld_go.zip ├── helloworld_go ├── .gitignore ├── README.md ├── _postGenerate.sh ├── build.sh └── main.go ├── helloworld_java_ant ├── .gitignore ├── README.md ├── _postGenerate.sh ├── build.xml ├── lib │ └── README.md └── src │ └── ${{=project.package[]=}} │ └── Entry.java ├── helloworld_java_mvn ├── .gitignore ├── README.md ├── _postGenerate.sh ├── pom.xml └── src │ ├── main │ ├── java │ │ └── ${{=project.package[]=}} │ │ │ └── Entry.java │ └── resources │ │ └── META-INF │ │ └── MANIFEST.MF │ └── test │ └── ${{=project.package[]=}} │ └── EntryTest.java ├── helloworld_ruby ├── ${{=project.name=}}.gemspec ├── Gemfile ├── README.md ├── Rakefile ├── bin │ └── ${{=project.name=}} ├── lib │ ├── ${{=project.name=}}.rb │ └── ${{=project.name=}} │ │ ├── core.rb │ │ └── version.rb └── spec │ ├── ${{=project.name=}} │ └── ${{=gem.class=}}_spec.rb │ └── spec_helper.rb └── library_python ├── ${{=project.name=}} ├── ${{=class.name=}}.py ├── __init__.py ├── data │ └── some_data.html └── helpers.py ├── .gitignore ├── LICENSE.txt ├── Makefile ├── README.md ├── _postGenerate.sh ├── bin └── ${{=project.name=}} ├── docs └── doc.txt ├── requirements-dev.txt ├── requirements.txt ├── setup.py └── tests ├── __init__.py └── test_helpers.py /.gitattributes: -------------------------------------------------------------------------------- 1 | samples/* linquist-vendored 2 | build.sh linquist-vendored 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pkg/ 2 | /src/ 3 | /.output/ 4 | /.temp/ 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | # Executable uses syscall and some file ops that are only properly 4 | # available in 1.2. 1.1 fails to build, and post-1.4 has trouble with syscall. 5 | go: 6 | - 1.2 7 | -------------------------------------------------------------------------------- /ADVANCED.md: -------------------------------------------------------------------------------- 1 | # Advanced usage 2 | 3 | ###Are there parameter naming restrictions? 4 | 5 | Yes. Parameters can be any combination of unicode code points that forms a series of runes. But, parameters must not contain square brackets (`[]`), and must not include either a semicolon, comma, or an equals sign (`;`, `,` or `=`), and cannot begin with a colon (`:`). 6 | 7 | Parameters _can_ begin with numbers, unlike other frameworks/parsers which prohibit this. 8 | 9 | As features emerge, further restrictions may apply. Any new feature that adds naming restrictions will try to stick to the ascii-range symbols. In general, try to keep your parameters alphanumeric, and you'll be fine. 10 | 11 | ###How do I make package paths? 12 | 13 | Parameters can be specified as a list by separating values with a comma, like so. 14 | 15 | wisk -p "project.package=com,example,sample" 16 | 17 | By default, if a parameter is referenced and the parameter is a list, only the first element in the list 18 | will be used. So using "${{=project.package=}}" with the above parameters will only result in "com". 19 | However, placeholders can specify a separator used to join the list elements together, like so; 20 | 21 | ${{=project.package[.]=}} 22 | 23 | In this case, the above will be replaced with "com.example.sample". This is useful for creating nested folder structures, or package names. See the Java examples in the "samples" folder for an implementation of this, using a single "project.package" parameter to create nested folder hierarchies and package declarations. 24 | 25 | Note that if no separator is specified, the default OS path separator is used instead. 26 | 27 | ###Can I inject parameters into a block of boilerplate? 28 | 29 | A "content placeholder" can be used to create a sequence of values, each using one value from the list of a single parameter. For instance; 30 | 31 | ${{=:project.properties=}} 32 | ${{value}}=TRUE 33 | ${{=;project.properties=}} 34 | 35 | Would use each value in "project.properties" to generate a line. Given the input: 36 | 37 | wisk -p "project.properties=foo,bar,baz,quux" 38 | 39 | The following would be generated: 40 | 41 | foo=TRUE 42 | bar=TRUE 43 | baz=TRUE 44 | quux=TRUE 45 | 46 | However, this "content placeholder" construct can be used recursively with the `recurse` reserved placeholder. This is primarily useful for things like Ruby module declarations. Given the below example; 47 | 48 | ${{=:project.module=}} 49 | module ${{value}} 50 | ${{recurse}} 51 | end 52 | ${{=;project.module=}} 53 | 54 | With the parameter being; 55 | 56 | wisk -p "project.module=My,Sample,Project" 57 | 58 | The result is: 59 | 60 | module My 61 | module Sample 62 | module Project 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: build 2 | all: package 3 | 4 | export GOPATH=$(CURDIR)/ 5 | export GOBIN=$(CURDIR)/.temp/ 6 | 7 | init: clean 8 | go get ./... 9 | 10 | build: init 11 | go build -o ./.output/wisk . 12 | 13 | test: 14 | go test 15 | go test -bench=. 16 | 17 | integrate: build 18 | @./.output/wisk -a ./samples/helloworld_ruby/ 19 | ./.output/wisk helloworld_ruby ./.populatedSample 20 | 21 | clean: 22 | @rm -rf ./.output/ 23 | 24 | dist: build test 25 | 26 | export GOOS=linux; \ 27 | export GOARCH=amd64; \ 28 | go build -o ./.output/wisk64 . 29 | 30 | export GOOS=linux; \ 31 | export GOARCH=386; \ 32 | go build -o ./.output/wisk32 . 33 | 34 | export GOOS=darwin; \ 35 | export GOARCH=amd64; \ 36 | go build -o ./.output/wisk_osx . 37 | 38 | export GOOS=windows; \ 39 | export GOARCH=amd64; \ 40 | go build -o ./.output/wisk.exe . 41 | 42 | package: dist 43 | 44 | ifeq ($(shell which fpm), ) 45 | @echo "FPM is not installed, no packages will be made." 46 | @echo "https://github.com/jordansissel/fpm" 47 | @exit 1 48 | endif 49 | 50 | ifeq ($(WISK_VERSION), ) 51 | 52 | @echo "No 'WISK_VERSION' was specified." 53 | @echo "Export a 'WISK_VERSION' environment variable to perform a package" 54 | @exit 1 55 | endif 56 | 57 | fpm \ 58 | --log error \ 59 | -s dir \ 60 | -t deb \ 61 | -v $(WISK_VERSION) \ 62 | -n wisk \ 63 | ./.output/wisk64=/usr/local/bin/wisk \ 64 | ./docs/wisk.7=/usr/share/man/man7/wisk.7 \ 65 | ./autocomplete/wisk=/etc/bash_completion.d/wisk 66 | 67 | fpm \ 68 | --log error \ 69 | -s dir \ 70 | -t deb \ 71 | -v $(WISK_VERSION) \ 72 | -n wisk \ 73 | -a i686 \ 74 | ./.output/wisk32=/usr/local/bin/wisk \ 75 | ./docs/wisk.7=/usr/share/man/man7/wisk.7 \ 76 | ./autocomplete/wisk=/etc/bash_completion.d/wisk 77 | 78 | @mv ./*.deb ./.output/ 79 | 80 | fpm \ 81 | --log error \ 82 | -s dir \ 83 | -t rpm \ 84 | -v $(WISK_VERSION) \ 85 | -n wisk \ 86 | ./.output/wisk64=/usr/local/bin/wisk \ 87 | ./docs/wisk.7=/usr/share/man/man7/wisk.7 \ 88 | ./autocomplete/wisk=/etc/bash_completion.d/wisk 89 | 90 | fpm \ 91 | --log error \ 92 | -s dir \ 93 | -t rpm \ 94 | -v $(WISK_VERSION) \ 95 | -n wisk \ 96 | -a i686 \ 97 | ./.output/wisk32=/usr/local/bin/wisk \ 98 | ./docs/wisk.7=/usr/share/man/man7/wisk.7 \ 99 | ./autocomplete/wisk=/etc/bash_completion.d/wisk 100 | 101 | @mv ./*.rpm ./.output/ 102 | 103 | dockerTest: 104 | ifeq ($(shell which docker), ) 105 | @echo "Docker is not installed." 106 | @exit 1 107 | endif 108 | 109 | containerized_build: dockerTest 110 | 111 | docker run \ 112 | --rm \ 113 | -v "$(CURDIR)":"/srv/build":rw \ 114 | -e ALT_VERSION=$(SEEDSTATS_VERSION) \ 115 | golang:1.13 \ 116 | bash -c \ 117 | "cd /srv/build; make build" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #wisk 2 | 3 | [![Build Status](https://travis-ci.org/Knetic/wisk.svg?branch=master)](https://travis-ci.org/Knetic/wisk) 4 | 5 | `wisk`generates new projects based on a project skeleton. This makes it easy to quickly build new projects without manually creating a lot of boilerplate files and folders. 6 | 7 | ### Why is this useful? 8 | 9 | You (or your company) probably makes projects with very common dependencies, patterns, names, metadata, and boilerplate code for every project. Updating this boilerplate content, or even making a new project, can be daunting, and probably involves a good amount of copy/paste, find/replace, and crossed fingers. With `wisk`, you can make a single skeleton by writing all of the dependencies, structure and conventions once - then re-using that to generate multiple projects. 10 | 11 | This tool lets you parameterize file contents, _file names_ and directory names. It seeks to completely eliminate copy/pasting and find/replacing when creating new projects. You should be able to run one command and have a fully-functional (and correctly-named) project ready to go immediately. 12 | 13 | ### Will this work for my favorite language? 14 | 15 | Probably! `wisk` can generate projects for anything that uses text files as its primary mode of representing project structure and data. I personally use it for Java (both standard and maven projects), Go, ruby, python, and Chef. 16 | 17 | The only case in which `wisk` will not work is for projects with specific binary-type files involved. If you want `wisk` to work with something like that, you're better off upgrading to a modern technology, or asking your vendor to support modern development workflows. 18 | 19 | ### How do I use it? 20 | 21 | `wisk` takes the path of a skeleton project and the desired output path, then copies the files from the skeleton to the output, like so. 22 | 23 | wisk ./skeleton ./cool_project 24 | 25 | If no parameters are given or used, this is equivalent to a `cp` operation. However, `wisk`'s strength is that it can substitute placeholders with parameters. For instance; 26 | 27 | wisk -p "project.name=fooject" ./skeleton ./cool_project 28 | 29 | Any placeholders named "project.name" will be replaced by "fooject" in the contents of any file, any file name, or any folder name. So, for instance, in a skeleton file whose contents look like: 30 | 31 | Welcome to ${{=project.name=}}! This project is pretty cool. 32 | 33 | After running wisk, the generated file will look like; 34 | 35 | Welcome to fooject! This project is pretty cool. 36 | 37 | You can give `wisk` multiple parameters to replace by semicolon-separating them; 38 | 39 | wisk -p "project.name=fooject;project.executable=foo" ./skeleton ./cool_project 40 | 41 | Placeholders can be literally anywhere in a plaintext file. `wisk` doesn't parse the file, it just looks for the placeholder tags. You can use them for classnames, module paths, import statements, variable names, README contents, or anywhere else. 42 | 43 | If a skeleton contains a parameter that is not specified, the generated project will have all instances of that placeholder replaced with a blank string. This may cause syntax errors, so it's best to always specify every parameter that you need. You can inspect the parameters a skeleton supports by using the `-i` flag, like so; 44 | 45 | wisk -i ./skeleton 46 | 47 | This flag works with any valid skeleton, including directories, archives, and registered skeletons. 48 | 49 | There are more features to `wisk`, if you're still curious about them you ought to read "ADVANCED.md" in this repository, or check out the "samples" directory - it has examples in many languages, some of which use more advanced features than others. In particular, the "helloworld_ruby" sample shows off every feature in `wisk`. 50 | 51 | ### How do I make skeletons? 52 | 53 | `wisk` accepts any directory as a possible skeleton, just make a folder anywhere and `wisk` will be able to use it. However, this makes it a little hard to share skeletons. So `wisk` also accepts a \*.zip archive. Like so; 54 | 55 | wisk ./skeleton.zip ./cool_project 56 | 57 | `wisk` will unzip the file to a temporary directory, then generate a new project based on the contents of the archive. 58 | 59 | You can also use "registered templates", which are archives stored per-user. These can be used purely by name, eliminating the need to know exactly where the template is stored. To register a template, create a zip archive of the templat, then use the `-a` flag, like so; 60 | 61 | wisk -a ./skeleton.zip 62 | 63 | Afterwards, you can use that same template by name. For example; 64 | 65 | wisk skeleton ./cool_project 66 | 67 | Which uses the "skeleton" template (as it was defined when you used the `-a` flag) as the template for "cool_project". 68 | 69 | After registration, you can list all registered project skeletons by using the `-l` flag, like so; 70 | 71 | wisk -l 72 | 73 | ### Can I run a script after wisking a new project? 74 | 75 | Absolutely! If the skeleton project contains a file named `_postGenerate.sh` at the top level, then `wisk` will execute that script after generating a project. 76 | 77 | The script's working directory will be set to the generated project's directory. 78 | 79 | Note that this may have security implications. Inspect post-generation scripts created by others before using project skeletons. 80 | 81 | ### Aren't there other projects that do this? 82 | 83 | Sort of. Maven and Gradle both had the notion of "archetypes", which is conceptually similar. There are projects like Mr. Bones for ruby, and even IDE-specific solutions such as Eclipse or Visual Studio's project templates. That's to say nothing of all the framework-specific project generators. But I've grown tired of learning a new template scheme and cli interface for every language or framework, I just wanted to have one set of templates that were all user-defined, easy to share, and all using a unified parameter interface. 84 | 85 | [Cookiecutter](https://github.com/audreyr/cookiecutter) is a cool project which meets similar goals, but has many drawbacks. It requires a python installation, needs either STDIN input or an *rc file, has logic-based templating, can't create templates from arbitrary directories or archives, seems to aim for monolithic templates, cannot do parameter joining or recursion, and doesn't seem to support post-generation scripts; making it difficult (if not impossible) to use for languages like Ruby, C-sharp, or Java (which I, at least, spend a lot of time in). `wisk` uses small, direct, purposeful skeletons to create many similar projects, it's not meant to make a monolithic language/framework template which fills every conceivable need that one may have of a project in that language/framework. 86 | 87 | ### Branching 88 | 89 | I use green masters, and heavily develop with private feature branches. Full releases are pinned and unchangeable, representing the best available version with the best documentation and test coverage. Master branch, however, should always have all tests pass and implementations considered "working", even if it's just a first pass. Master should never panic. 90 | 91 | ### License 92 | 93 | This project is licensed under the MIT general use license. You're free to integrate, fork, and play with this code as you feel fit without consulting the author, as long as you provide proper credit to the author in your works. 94 | 95 | ### Activity 96 | 97 | If this repository hasn't been updated in a while, it's probably because I don't have any outstanding issues to work on - it's not because I've abandoned the project. If you have questions, issues, or patches; I'm completely open to pull requests, issues opened on github, or emails from out of the blue. 98 | -------------------------------------------------------------------------------- /RunSettings.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "flag" 6 | "fmt" 7 | "path/filepath" 8 | "time" 9 | "strings" 10 | ) 11 | 12 | /* 13 | Represents arguments given by the user to this program. 14 | */ 15 | type RunSettings struct { 16 | parameters map[string][]string 17 | 18 | skeletonPath string 19 | targetPath string 20 | 21 | basicAuthUser string 22 | basicAuthPass string 23 | 24 | inspectionRun bool 25 | addRegistry bool 26 | showRegistry bool 27 | forceGenerate GenerateMode 28 | blankParameters bool 29 | 30 | flagList bool 31 | } 32 | 33 | type GenerateMode uint8 34 | 35 | const ( 36 | GENERATE_NONE GenerateMode = iota 37 | GENERATE_OVERWRITE 38 | GENERATE_DELETE 39 | ) 40 | 41 | var FLAGS = []string{ 42 | "-p", 43 | "-i", 44 | "-a", 45 | "-l", 46 | "-f", 47 | "-w", 48 | "-b", 49 | "-bu", 50 | "-bp", 51 | "-flags", 52 | } 53 | 54 | /* 55 | Parses runtime flags and positional arguments, returning the result. 56 | */ 57 | func FindRunSettings() (RunSettings, error) { 58 | 59 | var ret RunSettings 60 | var parameterGroup string 61 | var forceGenerate, forceDelete bool 62 | var err error 63 | 64 | flag.StringVar(¶meterGroup, "p", "", "Semicolon-separated list of parameters in k=v form.") 65 | flag.StringVar(&ret.basicAuthUser, "bu", "", "The 'user' to use when a remote archive requests Basic Authentication") 66 | flag.StringVar(&ret.basicAuthPass, "bp", "", "The 'password' to use when a remote archive requests Basic Authentication") 67 | flag.BoolVar(&ret.inspectionRun, "i", false, "Whether or not to show a list of available parameters for the skeleton") 68 | flag.BoolVar(&ret.addRegistry, "a", false, "Whether or not to register the template at the given path (can be http/https URLs)") 69 | flag.BoolVar(&ret.showRegistry, "l", false, "Whether or not to show a list of all available registered templates") 70 | flag.BoolVar(&forceGenerate, "f", false, "Whether or not to overwrite existing files during generation") 71 | flag.BoolVar(&forceDelete, "d", false, "Whether or not to delete every existing file in the output path first (only valid when -f is specified)") 72 | flag.BoolVar(&ret.blankParameters, "b", false, "Whether or not to replace unspecified parameters with blank strings") 73 | flag.BoolVar(&ret.flagList, "flags", false, "Whether or not to list the flags") 74 | flag.Parse() 75 | 76 | ret.skeletonPath = flag.Arg(0) 77 | ret.targetPath = flag.Arg(1) 78 | 79 | if(ret.flagList || ret.showRegistry) { 80 | return ret, nil 81 | } 82 | 83 | // if we're not just showing the registry, and not skeleton path is specified... 84 | if ret.skeletonPath == "" { 85 | errorMsg := fmt.Sprintf("Skeleton project path not specified") 86 | return ret, errors.New(errorMsg) 87 | } 88 | 89 | // if we're actually generating a project, and no target path is specified... 90 | if !ret.inspectionRun && 91 | !ret.addRegistry && 92 | ret.targetPath == "" { 93 | 94 | errorMsg := fmt.Sprintf("Target output path not specified") 95 | return ret, errors.New(errorMsg) 96 | } 97 | 98 | // set up overwrite strategy 99 | if(forceGenerate) { 100 | if(forceDelete) { 101 | ret.forceGenerate = GENERATE_DELETE 102 | } else { 103 | ret.forceGenerate = GENERATE_OVERWRITE 104 | } 105 | } else { 106 | ret.forceGenerate = GENERATE_NONE 107 | } 108 | 109 | // make parameters, set default project.name 110 | ret.parameters = make(map[string][]string) 111 | ret.parameters["project.name"] = []string{filepath.Base(ret.targetPath)} 112 | ret.parameters["project.createdDate"] = []string{time.Now().Format("2006-01-02")} 113 | 114 | err = parseParametersTo(parameterGroup, ret.parameters) 115 | if err != nil { 116 | return ret, err 117 | } 118 | 119 | return ret, nil 120 | } 121 | 122 | /* 123 | Given a sequence of k=v strings, this parses them out into a map. 124 | */ 125 | func parseParametersTo(parameterGroup string, destination map[string][]string) error { 126 | 127 | var groups, pair, values []string 128 | var key, value string 129 | 130 | parameterGroup = strings.Trim(parameterGroup, " ") 131 | 132 | if len(parameterGroup) == 0 { 133 | return nil 134 | } 135 | 136 | groups = strings.Split(parameterGroup, ";") 137 | if len(groups) == 0 { 138 | groups = []string{ 139 | parameterGroup, 140 | } 141 | } 142 | 143 | for _, group := range groups { 144 | 145 | pair = strings.Split(group, "=") 146 | 147 | if len(pair) != 2 { 148 | errorMsg := fmt.Sprintf("Unable to parse parameters, expected exactly one '=' per semicolon-separated set") 149 | return errors.New(errorMsg) 150 | } 151 | 152 | key = strings.Trim(pair[0], " ") 153 | value = strings.Trim(pair[1], " ") 154 | values = strings.Split(value, ",") 155 | 156 | if len(values) <= 0 { 157 | errorMsg := fmt.Sprintf("Unable to parse parameters, parameter '%s', value was empty\n", key) 158 | return errors.New(errorMsg) 159 | } 160 | 161 | destination[key] = values 162 | } 163 | 164 | return nil 165 | } 166 | -------------------------------------------------------------------------------- /StringSet.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | /* 4 | Represents a distinct set of strings. 5 | */ 6 | type StringSet struct { 7 | values []string 8 | } 9 | 10 | /* 11 | Adds a string to this set, if it does not already exist in the set. 12 | */ 13 | func (this *StringSet) Add(items... string) { 14 | 15 | for _, item := range items { 16 | if !this.Contains(item) { 17 | this.values = append(this.values, item) 18 | } 19 | } 20 | } 21 | 22 | /* 23 | Returns true if this set contains the given [item], false otherwise. 24 | */ 25 | func (this StringSet) Contains(item string) bool { 26 | 27 | for _, extant := range this.values { 28 | 29 | if extant == item { 30 | return true 31 | } 32 | } 33 | 34 | return false 35 | } 36 | 37 | /* 38 | Returns a slice representing all items contained by this set. 39 | */ 40 | func (this StringSet) GetSlice() []string { 41 | return this.values 42 | } 43 | 44 | func (this StringSet) Length() int { 45 | return len(this.values) 46 | } 47 | -------------------------------------------------------------------------------- /TemplateRegistry.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "github.com/jhoonb/archivex" 7 | "github.com/mitchellh/go-homedir" 8 | "io/ioutil" 9 | "net/http" 10 | "os" 11 | "net/url" 12 | "io" 13 | "path/filepath" 14 | "strings" 15 | ) 16 | 17 | /* 18 | Manages templates that live in a persistent template directory on the local disk. 19 | */ 20 | type TemplateRegistry struct { 21 | templatePaths StringSet 22 | path string 23 | } 24 | 25 | /* 26 | Creates a new registry located in the user's home directory. 27 | If this directory does not exist, it is created and left empty, returning and empty TemplateRegistry struct. 28 | If it exists, this will populate a new TemplateRegistry struct and return it. 29 | If the path is not readable, this returns an empty struct. 30 | */ 31 | func NewTemplateRegistry() *TemplateRegistry { 32 | 33 | var ret *TemplateRegistry 34 | var files []os.FileInfo 35 | var name string 36 | var err error 37 | 38 | ret = new(TemplateRegistry) 39 | 40 | ret.path, err = getRegistryPath() 41 | if err != nil { 42 | return ret 43 | } 44 | 45 | err = os.MkdirAll(ret.path, 0700) 46 | if err != nil { 47 | return ret 48 | } 49 | 50 | files, err = ioutil.ReadDir(ret.path) 51 | if err != nil { 52 | return ret 53 | } 54 | 55 | for _, file := range files { 56 | 57 | name = file.Name() 58 | 59 | // strip extension 60 | extensionIndex := len(filepath.Ext(name)) 61 | if extensionIndex > 0 { 62 | 63 | nameLen := len(name) 64 | name = name[0 : nameLen-extensionIndex] 65 | } 66 | 67 | ret.templatePaths.Add(name) 68 | } 69 | 70 | return ret 71 | } 72 | 73 | /* 74 | Returns true if this registry contains a template of the given [name], 75 | false otherwise. 76 | */ 77 | func (this TemplateRegistry) Contains(name string) bool { 78 | return this.templatePaths.Contains(name) 79 | } 80 | 81 | /* 82 | Returns true if the given path is something that should be interpreted 83 | as a registry template. 84 | */ 85 | func (this TemplateRegistry) IsPathRegistry(path string) bool { 86 | return !strings.Contains(path, string(os.PathSeparator)) && !strings.Contains(path, ".") 87 | } 88 | 89 | /* 90 | Returns a path for the expanded template identified by [name]. 91 | The path returned is temporary, and is not the "actual" location of the template, 92 | merely where it can be immediately read. 93 | The returned path should not be persisted. 94 | */ 95 | func (this TemplateRegistry) GetTemplatePath(name string) (string, error) { 96 | 97 | var path string 98 | 99 | if !this.Contains(name) { 100 | errorMsg := fmt.Sprintf("Cannot find any template by the name '%s'\n", name) 101 | return "", errors.New(errorMsg) 102 | } 103 | 104 | path = (this.path + name + ".zip") 105 | return filepath.Abs(path) 106 | } 107 | 108 | /* 109 | Registers the given [path] in the registry, by copying the archive file to it. 110 | If the file is not an archive, or it cannot be read, or the registry cannot be written, 111 | an error is returned. 112 | If the given [path] is remote (such as http), and if the server requires authentication, 113 | the given [username] and [password] will be used. 114 | If the path is local, username/password are inconsequential. 115 | */ 116 | func (this *TemplateRegistry) RegisterTemplate(path string, username string, password string) (string, error) { 117 | 118 | var targetPath, name string 119 | var err error 120 | 121 | // if this is a remote path, download as a zip to a temporary directory before trying to register. 122 | if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { 123 | 124 | path, err = downloadArchive(path, username, password) 125 | if(err != nil) { 126 | return "", err 127 | } 128 | } 129 | 130 | // if the given path is a directory (not a zip file), 131 | // archive it and prepare for registration. 132 | if !strings.HasSuffix(path, archiveMarker) { 133 | 134 | path, err = archivePath(path) 135 | if err != nil { 136 | return "", err 137 | } 138 | } 139 | 140 | name = filepath.Base(path) 141 | targetPath = fmt.Sprintf("%s%s%s", this.path, string(os.PathSeparator), name) 142 | 143 | _, err = CopyFile(path, targetPath) 144 | return name, err 145 | } 146 | 147 | /* 148 | Downloads the given [url] to a temporary directory (as a .zip). 149 | Returns the temporary path to the downloaded archive, or an error if it encountered one. 150 | */ 151 | func downloadArchive(targetURL string, username string, password string) (string, error) { 152 | 153 | var request *http.Request 154 | var response *http.Response 155 | var client http.Client 156 | var outputFile *os.File 157 | var parsedURL *url.URL 158 | var outputPath string 159 | var baseName string 160 | var err error 161 | 162 | outputPath, err = ioutil.TempDir("", "wiskRemoteArchive") 163 | if(err != nil) { 164 | return "", err 165 | } 166 | 167 | parsedURL, err = url.Parse(targetURL) 168 | if(err != nil) { 169 | return "", err 170 | } 171 | 172 | request, err = http.NewRequest("GET", targetURL, nil) 173 | if(err != nil) { 174 | return "", err 175 | } 176 | request.SetBasicAuth(username, password) 177 | 178 | baseName = filepath.Base(parsedURL.Path) 179 | baseName = strings.TrimSuffix(baseName, filepath.Ext(baseName)) 180 | outputPath = filepath.Join(outputPath, baseName + ".zip") 181 | outputPath, _ = filepath.Abs(outputPath) 182 | 183 | outputFile, err = os.Create(outputPath) 184 | if(err != nil) { 185 | return "", err 186 | } 187 | defer outputFile.Close() 188 | 189 | response, err = client.Do(request) 190 | if(err != nil) { 191 | return "", err 192 | } 193 | 194 | if(!strings.Contains(response.Status, "200")) { 195 | errorMsg := fmt.Sprintf("Unable to download remote archive: HTTP %s\n", response.Status) 196 | return "", errors.New(errorMsg) 197 | } 198 | 199 | _, err = io.Copy(outputFile, response.Body) 200 | if(err != nil) { 201 | return "", err 202 | } 203 | return outputPath, nil 204 | } 205 | 206 | func archivePath(path string) (string, error) { 207 | 208 | var zip archivex.ZipFile 209 | var name string 210 | var tempPath string 211 | var err error 212 | 213 | tempPath, err = ioutil.TempDir("", "") 214 | if err != nil { 215 | return "", err 216 | } 217 | 218 | name = filepath.Base(path) 219 | tempPath = fmt.Sprintf("%s%s%s.zip", tempPath, string(os.PathSeparator), name) 220 | 221 | zip.Create(tempPath) 222 | zip.AddAll(path, false) 223 | zip.Close() 224 | 225 | return tempPath, nil 226 | } 227 | 228 | /* 229 | Returns a slice representing every template in this registry. 230 | */ 231 | func (this TemplateRegistry) GetTemplateList() []string { 232 | return this.templatePaths.GetSlice() 233 | } 234 | 235 | func getRegistryPath() (string, error) { 236 | 237 | var ret string 238 | var err error 239 | 240 | ret, err = homedir.Dir() 241 | if err != nil { 242 | errorMsg := fmt.Sprintf("Unable to determine user home directory: %s\n", err.Error()) 243 | return "", errors.New(errorMsg) 244 | } 245 | 246 | ret, err = homedir.Expand(ret) 247 | if err != nil { 248 | errorMsg := fmt.Sprintf("Unable to expand home directory: %s\n", err.Error()) 249 | return "", errors.New(errorMsg) 250 | } 251 | 252 | return fmt.Sprintf("%s%s.wisk/", ret, string(os.PathSeparator)), nil 253 | } 254 | -------------------------------------------------------------------------------- /TemplatedFile.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | ) 7 | 8 | /* 9 | Represents a single file that is part of a project skeleton. 10 | */ 11 | type TemplatedFile struct { 12 | path string 13 | mode os.FileMode 14 | } 15 | 16 | /* 17 | Returns a new templated file, with the given [path], [root] path of the project skeleton, 18 | and the given filemode [info]. 19 | */ 20 | func NewTemplatedFile(path string, root string, info os.FileInfo) TemplatedFile { 21 | 22 | var ret TemplatedFile 23 | 24 | ret.path = strings.Replace(path, root, "", -1) 25 | ret.mode = info.Mode() 26 | 27 | return ret 28 | } 29 | -------------------------------------------------------------------------------- /TemplatedProject.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "os" 9 | "path/filepath" 10 | "strings" 11 | ) 12 | 13 | const ( 14 | PLACEHOLDER_OPEN = "${{=" 15 | PLACEHOLDER_CLOSE = "=}}" 16 | 17 | PARAMETER_JOIN_OPEN = "[" 18 | PARAMETER_JOIN_CLOSE = "]" 19 | 20 | PLACEHOLDER_ITERATIVE_VALUE = "${{value}}" 21 | PLACEHOLDER_ITERATIVE_RECURSE = "${{recurse}}" 22 | PLACEHOLDER_ITERATIVE_RECURSE_LN = "${{recurse}}\n" 23 | 24 | archiveMarker = ".zip" 25 | ) 26 | 27 | /* 28 | Represents an entire skeleton project, capable of generating new projects. 29 | */ 30 | type TemplatedProject struct { 31 | files []TemplatedFile 32 | rootDirectory string 33 | 34 | missingParameters StringSet 35 | incorrectParameters StringSet 36 | } 37 | 38 | /* 39 | Creates a new skeleton project rooted at the given [path]. 40 | Every file below that path (of any size or location) is included. 41 | */ 42 | func NewTemplatedProject(path string) (*TemplatedProject, error) { 43 | 44 | var tempDir string 45 | var err error 46 | 47 | path, err = filepath.Abs(path) 48 | if err != nil { 49 | return nil, err 50 | } 51 | 52 | // extract archive to temporary directory, then read it. 53 | if strings.HasSuffix(path, archiveMarker) { 54 | 55 | tempDir, err = ioutil.TempDir("", "") 56 | if err != nil { 57 | return nil, err 58 | } 59 | 60 | Unzip(path, tempDir) 61 | return createTemplatedProjectFromFile(tempDir) 62 | } 63 | return createTemplatedProjectFromFile(path) 64 | } 65 | 66 | func createTemplatedProjectFromFile(path string) (*TemplatedProject, error) { 67 | 68 | var ret *TemplatedProject 69 | var stat os.FileInfo 70 | var err error 71 | 72 | stat, err = os.Stat(path) 73 | if err != nil { 74 | return nil, err 75 | } 76 | 77 | if !stat.IsDir() { 78 | return nil, errors.New("Path is not a directory") 79 | } 80 | 81 | ret = new(TemplatedProject) 82 | ret.rootDirectory = path 83 | 84 | err = filepath.Walk(path, ret.getFolderWalker()) 85 | return ret, err 86 | } 87 | 88 | /* 89 | Creates a copy of this project's template at the given [targetPath] 90 | using the given [parameters]. 91 | */ 92 | func (this *TemplatedProject) GenerateAt(targetPath string, parameters map[string][]string) error { 93 | 94 | var file TemplatedFile 95 | var inputPath, outputPath string 96 | var err error 97 | 98 | for _, file = range this.files { 99 | 100 | outputPath = (targetPath + file.path) 101 | outputPath, err = filepath.Abs(outputPath) 102 | if err != nil { 103 | return err 104 | } 105 | 106 | inputPath = (this.rootDirectory + file.path) 107 | outputPath = this.replaceStringParameters(outputPath, parameters) 108 | 109 | if strings.HasSuffix(outputPath, "/") { 110 | fmt.Printf("Could not create file at '%s', because the file name is empty.\n", outputPath) 111 | continue 112 | } 113 | 114 | err = this.replaceFileContents(inputPath, outputPath, file.mode, parameters) 115 | 116 | if err != nil { 117 | return err 118 | } 119 | } 120 | 121 | return nil 122 | } 123 | 124 | /* 125 | Returns a deduplicated list of all parameters used by this skeleton. 126 | */ 127 | func (this TemplatedProject) FindParameters() ([]string, error) { 128 | 129 | var file TemplatedFile 130 | var parameters StringSet 131 | var contentBytes []byte 132 | var inputPath string 133 | var err error 134 | 135 | for _, file = range this.files { 136 | 137 | inputPath = (this.rootDirectory + file.path) 138 | parameters.Add(this.findParametersInString(file.path)...) 139 | 140 | contentBytes, err = ioutil.ReadFile(inputPath) 141 | if err != nil { 142 | return nil, err 143 | } 144 | 145 | parameters.Add(this.findParametersInString(string(contentBytes))...) 146 | } 147 | 148 | return parameters.GetSlice(), nil 149 | } 150 | 151 | func (this *TemplatedProject) findParametersInString(target string) []string { 152 | 153 | var parameters StringSet 154 | var characters chan rune 155 | var sequence string 156 | var exists bool 157 | 158 | characters = make(chan rune) 159 | go readRunes(target, characters) 160 | 161 | for { 162 | 163 | sequence, exists = readUntil(PLACEHOLDER_OPEN, characters) 164 | if !exists { 165 | break 166 | } 167 | 168 | // read a parameter, then replace it. 169 | sequence, exists = readUntil(PLACEHOLDER_CLOSE, characters) 170 | if !exists { 171 | break 172 | } 173 | 174 | // content placeholder? 175 | if sequence[0:1] == ":" || sequence[0:1] == ";" { 176 | sequence = sequence[1:len(sequence)] 177 | } 178 | 179 | // joined list? 180 | index := strings.LastIndex(sequence, PARAMETER_JOIN_OPEN) 181 | if index > 0 { 182 | sequence = sequence[0:index] 183 | } 184 | 185 | parameters.Add(sequence) 186 | } 187 | 188 | return parameters.GetSlice() 189 | } 190 | 191 | /* 192 | Reads the contents of the file at [inPath], replaces placeholders with the given [parameters], 193 | then writes the results to the given [outPath] (with the given [mode]). 194 | Any directories that do not exist in the [outPath] tree will be created. 195 | */ 196 | func (this *TemplatedProject) replaceFileContents(inPath, outPath string, mode os.FileMode, parameters map[string][]string) error { 197 | 198 | var contentBytes []byte 199 | var contents, path, base string 200 | var err error 201 | 202 | path, err = filepath.Abs(inPath) 203 | if err != nil { 204 | return err 205 | } 206 | 207 | contentBytes, err = ioutil.ReadFile(path) 208 | if err != nil { 209 | return err 210 | } 211 | 212 | // ensure base path exists 213 | base = fmt.Sprintf("%s%s", string(os.PathSeparator), filepath.Base(outPath)) 214 | index := strings.LastIndex(outPath, base) 215 | base = (outPath[0:index]) 216 | 217 | err = os.MkdirAll(base, 0755) 218 | if err != nil { 219 | return err 220 | } 221 | 222 | // write replaced contents 223 | contents = string(contentBytes) 224 | contents = this.replaceStringParameters(contents, parameters) 225 | 226 | err = ioutil.WriteFile(outPath, []byte(contents), mode) 227 | return err 228 | } 229 | 230 | /* 231 | Replaces all placeholders in the given [input] with their equivalent values in [parameters], 232 | returning the resultant string. 233 | */ 234 | func (this *TemplatedProject) replaceStringParameters(input string, parameters map[string][]string) string { 235 | 236 | var characters chan rune 237 | var sequence, separator, parameterName string 238 | var parameterValues []string 239 | var exists bool 240 | 241 | characters = make(chan rune) 242 | go readRunes(input, characters) 243 | 244 | resultBuffer := bytes.NewBuffer([]byte{}) 245 | 246 | for { 247 | 248 | sequence, exists = readUntil(PLACEHOLDER_OPEN, characters) 249 | resultBuffer.WriteString(sequence) 250 | 251 | if !exists { 252 | break 253 | } 254 | 255 | // read a parameter, then replace it. 256 | sequence, exists = readUntil(PLACEHOLDER_CLOSE, characters) 257 | 258 | if !exists { 259 | resultBuffer.WriteString(PLACEHOLDER_OPEN) 260 | resultBuffer.WriteString(sequence) 261 | break 262 | } 263 | 264 | // write parameter. If the parameter is unspecified, add it to the list of missing parameters. 265 | 266 | // check if the parameter has a separator 267 | exists, parameterName, separator = determineParameterSeparator(sequence) 268 | if exists { 269 | 270 | parameterValues, exists = parameters[parameterName] 271 | 272 | if !exists { 273 | this.missingParameters.Add(parameterName) 274 | } else { 275 | 276 | if(len(parameterValues) == 1) { 277 | this.incorrectParameters.Add(parameterName) 278 | } 279 | 280 | sequence = strings.Join(parameterValues, separator) 281 | resultBuffer.WriteString(sequence) 282 | } 283 | continue 284 | } 285 | 286 | // is this a content placeholder? 287 | if sequence[0:1] == ":" { 288 | 289 | parameterName = sequence[1:len(sequence)] 290 | sequence, exists = readUntil(fmt.Sprintf("${{=;%s=}}", parameterName), characters) 291 | 292 | // no closing content identifier? 293 | if !exists { 294 | resultBuffer.WriteString(sequence) 295 | continue 296 | } 297 | 298 | parameterValues, exists = parameters[parameterName] 299 | if !exists { 300 | this.missingParameters.Add(parameterName) 301 | continue 302 | } 303 | 304 | sequence = this.fillContentPlaceholder(parameterValues, sequence, parameters) 305 | resultBuffer.WriteString(sequence) 306 | continue 307 | } 308 | 309 | // this must be a normal parameter. 310 | parameterValues, exists = parameters[sequence] 311 | if !exists { 312 | this.missingParameters.Add(sequence) 313 | } else { 314 | resultBuffer.WriteString(parameterValues[0]) 315 | } 316 | } 317 | 318 | return resultBuffer.String() 319 | } 320 | 321 | /* 322 | Given the contents of a content placeholder and a specific parameter name / parameters, this 323 | returns a string which represents the exploded/replaced content. 324 | */ 325 | func (this *TemplatedProject) fillContentPlaceholder(parameterValues []string, contents string, parameters map[string][]string) string { 326 | 327 | var ret bytes.Buffer 328 | var contentTemplate, replaced, current string 329 | var recurseTemplate string 330 | var recursive bool 331 | 332 | // explode any inner content placeholders or regular placeholders. 333 | contentTemplate = this.replaceStringParameters(contents, parameters) 334 | contentTemplate = strings.TrimLeft(contentTemplate, " \t\n") 335 | 336 | current = PLACEHOLDER_ITERATIVE_RECURSE_LN 337 | recursive = strings.Index(contentTemplate, PLACEHOLDER_ITERATIVE_RECURSE) > 0 338 | 339 | if recursive { 340 | 341 | if strings.Index(contentTemplate, PLACEHOLDER_ITERATIVE_RECURSE_LN) > 0 { 342 | recurseTemplate = PLACEHOLDER_ITERATIVE_RECURSE_LN 343 | } else { 344 | recurseTemplate = PLACEHOLDER_ITERATIVE_RECURSE 345 | } 346 | } 347 | 348 | // iterate over every item in the list of parameter values, replacing "${{value}}" with the current item. 349 | for _, value := range parameterValues { 350 | 351 | replaced = strings.Replace(contentTemplate, PLACEHOLDER_ITERATIVE_VALUE, value, 1) 352 | 353 | // if this is a recursive template, replace the recursion indicator 354 | // with the replaced value. 355 | if recursive { 356 | 357 | current = strings.Replace(current, recurseTemplate, replaced, 1) 358 | } else { 359 | // otherwise, just append. 360 | ret.WriteString(replaced) 361 | } 362 | } 363 | 364 | if recursive { 365 | 366 | current = strings.Replace(current, PLACEHOLDER_ITERATIVE_RECURSE, "", 1) 367 | return current 368 | } 369 | return ret.String() 370 | } 371 | 372 | func determineParameterSeparator(parameter string) (exists bool, name string, separator string) { 373 | 374 | var start, end int 375 | 376 | start = strings.LastIndex(parameter, PARAMETER_JOIN_OPEN) 377 | end = strings.LastIndex(parameter, PARAMETER_JOIN_CLOSE) 378 | 379 | if start > 0 && end > 0 { 380 | 381 | separator = parameter[start+1 : end] 382 | if len(separator) <= 0 { 383 | separator = string(os.PathSeparator) 384 | } 385 | 386 | return true, parameter[0:start], separator 387 | } 388 | 389 | return false, "", "" 390 | } 391 | 392 | /* 393 | Creates a directory walker that discovers files and appends then into this templatedProject's 394 | list of files. 395 | */ 396 | func (this *TemplatedProject) getFolderWalker() func(string, os.FileInfo, error) error { 397 | 398 | var scmPaths []string 399 | var scmPath bytes.Buffer 400 | 401 | scmPath.WriteString(".git") 402 | scmPath.WriteRune(os.PathSeparator) 403 | 404 | scmPaths = []string { 405 | scmPath.String(), 406 | } 407 | 408 | return func(path string, fileStat os.FileInfo, err error) error { 409 | 410 | var file TemplatedFile 411 | 412 | if fileStat.IsDir() { 413 | return nil 414 | } 415 | 416 | // Check to see if the path is underneath an SCM root (like ".git") 417 | for _, forbiddenPath := range scmPaths { 418 | if(strings.Contains(path, forbiddenPath)) { 419 | return nil 420 | } 421 | } 422 | 423 | file = NewTemplatedFile(path, this.rootDirectory, fileStat) 424 | this.files = append(this.files, file) 425 | 426 | return nil 427 | } 428 | } 429 | 430 | /* 431 | Reads all runes individually from the given [input], 432 | writing each of them into the given [results] channel. 433 | Closes the channel after all runes have been read. 434 | */ 435 | func readRunes(input string, results chan rune) { 436 | 437 | for _, character := range input { 438 | 439 | results <- character 440 | } 441 | 442 | close(results) 443 | } 444 | 445 | /* 446 | Reads from the given channel until the given [pattern] is found. 447 | Returns a string representing all characters not part of the pattern, 448 | and a bool representing whether or not the end of the channel was reached 449 | before a pattern was found. 450 | */ 451 | func readUntil(pattern string, characters chan rune) (string, bool) { 452 | 453 | var sequence string 454 | var character rune 455 | var index int 456 | var done bool 457 | 458 | buffer := bytes.NewBuffer([]byte{}) 459 | 460 | for { 461 | 462 | character, done = <-characters 463 | 464 | if !done { 465 | return buffer.String(), false 466 | } 467 | 468 | buffer.WriteString(string(character)) 469 | sequence = buffer.String() 470 | index = strings.LastIndex(sequence, pattern) 471 | 472 | if index >= 0 { 473 | 474 | // remove pattern from sequence 475 | return sequence[0:index], true 476 | } 477 | } 478 | } 479 | -------------------------------------------------------------------------------- /archive.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Shamelessly stolen from http://stackoverflow.com/a/24792688/860453 4 | import ( 5 | "archive/zip" 6 | "io" 7 | "os" 8 | "path/filepath" 9 | ) 10 | 11 | func Unzip(src, dest string) error { 12 | r, err := zip.OpenReader(src) 13 | if err != nil { 14 | return err 15 | } 16 | defer func() { 17 | if err := r.Close(); err != nil { 18 | panic(err) 19 | } 20 | }() 21 | 22 | os.MkdirAll(dest, 0755) 23 | 24 | // Closure to address file descriptors issue with all the deferred .Close() methods 25 | extractAndWriteFile := func(f *zip.File) error { 26 | rc, err := f.Open() 27 | if err != nil { 28 | return err 29 | } 30 | defer func() { 31 | if err := rc.Close(); err != nil { 32 | panic(err) 33 | } 34 | }() 35 | 36 | path := filepath.Join(dest, f.Name) 37 | 38 | if f.FileInfo().IsDir() { 39 | os.MkdirAll(path, f.Mode()) 40 | } else { 41 | f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) 42 | if err != nil { 43 | return err 44 | } 45 | defer func() { 46 | if err := f.Close(); err != nil { 47 | panic(err) 48 | } 49 | }() 50 | 51 | _, err = io.Copy(f, rc) 52 | if err != nil { 53 | return err 54 | } 55 | } 56 | return nil 57 | } 58 | 59 | for _, f := range r.File { 60 | err := extractAndWriteFile(f) 61 | if err != nil { 62 | return err 63 | } 64 | } 65 | 66 | return nil 67 | } 68 | -------------------------------------------------------------------------------- /autocomplete/wisk: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Provides autocomplete functionality for wisk. 4 | 5 | completion() 6 | { 7 | local current=${COMP_WORDS[${COMP_CWORD}]} 8 | 9 | findArgCount 10 | determineEndFlags 11 | 12 | # Flag list. 13 | if [[ ${HAS_FLAGS} == false || "${current}" == -* ]]; 14 | then 15 | local flags=$(wisk -flags) 16 | COMPREPLY=($(compgen -W "${flags}" -- ${current})) 17 | return 18 | fi 19 | 20 | # Projects list 21 | if [[ ${CAN_LIST_PROJECTS} == true && "${COMP_POSITIONALS}" == 0 ]]; 22 | then 23 | local projects=$(wisk -l) 24 | COMPREPLY=($(compgen -W "${projects}" -- $current)) 25 | return 26 | fi 27 | 28 | # Directory target 29 | if [[ ${CAN_LIST_DIRECTORIES} == true ]]; 30 | then 31 | COMPREPLY=($(compgen -f "${current}")) 32 | return 33 | fi 34 | } 35 | 36 | # Finds the amount of positional args in "COMP_LINE", setting "COMP_POSITIONALS" to the result. 37 | findArgCount() 38 | { 39 | local result=-1 40 | local skip=false 41 | 42 | for word in "${COMP_WORDS[@]}" 43 | do 44 | if [[ ${word} == [[:space:]] ]]; 45 | then 46 | continue 47 | fi 48 | 49 | if [[ ${skip} == true ]]; 50 | then 51 | skip=false 52 | continue 53 | fi 54 | 55 | if [[ "${word}" == -* ]]; 56 | then 57 | skip=true 58 | continue 59 | fi 60 | 61 | result=$(expr "${result}" + 1) 62 | done 63 | 64 | COMP_POSITIONALS=${result} 65 | } 66 | 67 | # Determines if the "COMP_WORDS" contains an "end" flag, or a flag that should not be followed by positional arguments. 68 | determineEndFlags() 69 | { 70 | HAS_FLAGS=false 71 | CAN_LIST_PROJECTS=true 72 | CAN_LIST_DIRECTORIES=true 73 | 74 | for word in "${COMP_WORDS[@]}" 75 | do 76 | if [[ "${word}" == -* ]]; 77 | then 78 | HAS_FLAGS=true 79 | fi 80 | 81 | if [[ "${word}" == "-l" ]]; 82 | then 83 | CAN_LIST_DIRECTORIES=false 84 | CAN_LIST_PROJECTS=false 85 | return 86 | fi 87 | 88 | if [[ "${word}" == "-a" ]]; 89 | then 90 | CAN_LIST_PROJECTS=false 91 | return 92 | fi 93 | 94 | if [[ "${word}" == "-i" ]]; 95 | then 96 | CAN_LIST_DIRECTORIES=false 97 | return 98 | fi 99 | done 100 | } 101 | 102 | complete -F completion wisk 103 | -------------------------------------------------------------------------------- /docs/wisk.7: -------------------------------------------------------------------------------- 1 | .TH wisk 7 "2015-10-22" "version 1.5" 2 | 3 | .SH NAME 4 | wisk 5 | 6 | .SH SYNOPSIS 7 | 8 | Create projects from parameterized templates 9 | 10 | .SH DESCRIPTION 11 | 12 | wisk creates projects from parameterized templates. 13 | 14 | .SH OPTIONS 15 | 16 | wisk [-p] [-l] [-a] [-i] [-f] [-d] 17 | 18 | Usage: 19 | 20 | .IP -l 21 | Causes the program to list all registered templates by name, then immediately exit. 22 | .IP -i 23 | Causes the program to inspect the given skeleton (by positional argument 1), print out all of that skeleton's possible parameters, then exit. 24 | .IP -a 25 | Causes the program to register the given path (by positional argument 1) as a template. If the path is a *.zip file, it is added to the user's skeleton registry as-is. If the path is a directory, that directory is zipped and added to the user's skeleton registry. If the path is prefixed with 'http://' or 'https://', the remote archive will be downloaded and registered. In no case will this command ever modify the given directory. 26 | .IP -p 27 | Specifies parameters to be used when populating the target project. See "Parameters" for details. 28 | .IP -f 29 | Causes the program to overwrite any existing files in the output directory. 30 | .IP -d 31 | If used with -f, causes the program to delete the output directory (if it exists) before trying to generate the project. 32 | 33 | .SH PARAMETERS 34 | Parameters given to the "-p" flag are expected to be key=value format inside a single string, semicolon-delimited. Example below: 35 | 36 | .RS 37 | .br 38 | wisk -p "project.param.1=something; project.param.2=foobar" 39 | .RE 40 | 41 | Parameters can be specified as a list by comma-delimiting values. The following example would define "project.list" as a list of values, 42 | equalling ["foo", "bar", "baz", "quux"] 43 | 44 | .RS 45 | .br 46 | wisk -p "project.list=foo,bar,baz,quux" 47 | .RE 48 | 49 | .SH PLACEHOLDERS 50 | 51 | Placeholders inside of project skeletons should be in the following format: 52 | 53 | .RS 54 | .br 55 | ${{=parameter=}} 56 | .RE 57 | 58 | By convention, parameter names are dot-namespaced. Best practice is to never camelCase, snake-case, or flat_case parameter names. 59 | Use a namespace approach such as "project.name". 60 | 61 | Placeholders can begin with numbers, unlike other frameworks. 62 | Parameters must not contain square brackets, semicolon, comma, or equals sign ( [ ] ; , = ), and must not begin with a colon ( : ). 63 | 64 | .SH PARAMETER JOINS 65 | 66 | Placeholders can specify a join character for lists by using the square brackets: 67 | 68 | .RS 69 | .br 70 | ${{=parameter[::]=}} 71 | .RE 72 | 73 | If that skeleton was given a "parameter" value of "foo,bar,baz,quux", the resulting written value would be "foo::bar::baz::quux". 74 | 75 | .SH CONTENT AND RECURSIVE PLACEHOLDERS 76 | A "content placeholder" can be used to create a sequence of values, each using one value from the list of a single parameter. For instance; 77 | 78 | .RS 79 | .br 80 | ${{=:project.properties=}} 81 | .br 82 | ${{value}}=TRUE 83 | .br 84 | ${{=;project.properties=}} 85 | .RE 86 | 87 | Would use each value in "project.properties" to generate a line. Given the input: 88 | 89 | .RS 90 | .br 91 | wisk -p "project.properties=foo,bar,baz,quux" 92 | .RE 93 | 94 | The following would be generated: 95 | 96 | .RS 97 | .br 98 | foo=TRUE 99 | .br 100 | bar=TRUE 101 | .br 102 | baz=TRUE 103 | .br 104 | quux=TRUE 105 | .RE 106 | 107 | However, this "content placeholder" construct can be used recursively with the recurse reserved placeholder. This is primarily useful for things like Ruby module declarations. Given the below example; 108 | 109 | .RS 110 | .br 111 | ${{=:project.module=}} 112 | .br 113 | module ${{value}} 114 | .br 115 | ${{recurse}} 116 | .br 117 | end 118 | .br 119 | ${{=;project.module=}} 120 | .RE 121 | 122 | With the parameter being; 123 | 124 | .RS 125 | .br 126 | wisk -p "project.module=My,Sample,Project" 127 | .RE 128 | 129 | The result is: 130 | 131 | .RS 132 | .br 133 | module My 134 | .br 135 | module Sample 136 | .br 137 | module Project 138 | .br 139 | end 140 | .br 141 | end 142 | .br 143 | end 144 | .RE 145 | 146 | .SH AUTHOR 147 | George Lester (glester491@gmail.com) 148 | https://github.com/Knetic/wisk 149 | -------------------------------------------------------------------------------- /fileutil.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // A file for content shamelessly stolen from 4 | // http://stackoverflow.com/a/22259280/860453 5 | import ( 6 | "fmt" 7 | "io" 8 | "os" 9 | ) 10 | 11 | func CopyFile(src, dst string) (int64, error) { 12 | src_file, err := os.Open(src) 13 | if err != nil { 14 | return 0, err 15 | } 16 | defer src_file.Close() 17 | 18 | src_file_stat, err := src_file.Stat() 19 | if err != nil { 20 | return 0, err 21 | } 22 | 23 | if !src_file_stat.Mode().IsRegular() { 24 | return 0, fmt.Errorf("%s is not a regular file", src) 25 | } 26 | 27 | dst_file, err := os.Create(dst) 28 | if err != nil { 29 | return 0, err 30 | } 31 | defer dst_file.Close() 32 | return io.Copy(dst_file, src_file) 33 | } 34 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | ) 7 | 8 | func main() { 9 | 10 | var registry *TemplateRegistry 11 | var settings RunSettings 12 | var err error 13 | 14 | registry = NewTemplateRegistry() 15 | 16 | settings, err = FindRunSettings() 17 | if err != nil { 18 | exitWith("Unable to parse run arguments: %s\n", err, 1) 19 | return 20 | } 21 | 22 | if(settings.flagList) { 23 | 24 | for _, flag := range FLAGS { 25 | fmt.Println(flag) 26 | } 27 | return 28 | } 29 | 30 | registry = NewTemplateRegistry() 31 | 32 | // is the user showing the registry? 33 | if settings.showRegistry { 34 | showRegistry(registry) 35 | return 36 | } 37 | 38 | // is the user trying to add to the current registry? 39 | if settings.addRegistry { 40 | addRegistry(settings, registry) 41 | return 42 | } 43 | 44 | createProject(settings, registry) 45 | } 46 | 47 | func showRegistry(registry *TemplateRegistry) { 48 | 49 | for _, template := range registry.GetTemplateList() { 50 | fmt.Println(template) 51 | } 52 | } 53 | 54 | func addRegistry(settings RunSettings, registry *TemplateRegistry) { 55 | 56 | var name string 57 | var err error 58 | 59 | name, err = registry.RegisterTemplate(settings.skeletonPath, settings.basicAuthUser, settings.basicAuthPass) 60 | if err != nil { 61 | 62 | // TODO: I'm deeply uncomfortable with using "exitWith" outside of the actual 63 | // main method. This is too easy to let "exiting" become a separate code path. 64 | exitWith("Unable to register template: %s\n", err, 1) 65 | } 66 | 67 | fmt.Printf("Registered template '%s'\n", name) 68 | return 69 | } 70 | 71 | func createProject(settings RunSettings, registry *TemplateRegistry) { 72 | 73 | var project *TemplatedProject 74 | var parameters []string 75 | var err error 76 | 77 | // is this a registry skeleton? 78 | if registry.IsPathRegistry(settings.skeletonPath) && registry.Contains(settings.skeletonPath) { 79 | 80 | settings.skeletonPath, err = registry.GetTemplatePath(settings.skeletonPath) 81 | if err != nil { 82 | exitWith("Unable to expand registered template: %s\n", err, 1) 83 | return 84 | } 85 | } 86 | 87 | // Create templated project, in preparation for later use 88 | project, err = NewTemplatedProject(settings.skeletonPath) 89 | if err != nil { 90 | exitWith("Unable to read templated project: %s\n", err, 1) 91 | return 92 | } 93 | 94 | // inspect only? 95 | if settings.inspectionRun { 96 | 97 | parameters, err = project.FindParameters() 98 | 99 | if err != nil { 100 | exitWith("Unable to inspect skeleton: %s\n", err, 1) 101 | return 102 | } 103 | 104 | for _, parameter := range parameters { 105 | fmt.Println(parameter) 106 | } 107 | return 108 | } 109 | 110 | // check to see if the destination exists 111 | _, err = os.Stat(settings.targetPath) 112 | if(err == nil) { 113 | 114 | // if we force-generate, see which type of force generation to do (delete or overwrite) 115 | switch settings.forceGenerate { 116 | case GENERATE_NONE: 117 | fmt.Println("Destination path already exists, and no '-f' option was specified. Use '-f' to overwrite existing files.") 118 | return 119 | case GENERATE_DELETE: 120 | err = os.RemoveAll(settings.targetPath) 121 | if(err != nil) { 122 | exitWith("Unable to delete existing files in the given output directory: %s\n", err, 1) 123 | return 124 | } 125 | default: 126 | break 127 | } 128 | } 129 | 130 | // generate a project 131 | err = project.GenerateAt(settings.targetPath, settings.parameters) 132 | if err != nil { 133 | exitWith("Unable to generate project: %s\n", err, 1) 134 | return 135 | } 136 | 137 | // if everything succeeded, but we had missing parameters, make a note of it to the user. 138 | if project.missingParameters.Length() > 0 { 139 | 140 | if(settings.blankParameters) { 141 | 142 | // if blank parameters are allowed, print a message about how blank parameters were used. 143 | fmt.Printf("Project generated, but some parameters were not specified, and have been left blank:\n") 144 | } else { 145 | 146 | // if blank parameters are not allowed, delete the generated project. 147 | fmt.Printf("Project cannot be generated, some parameters were not specified:\n") 148 | os.RemoveAll(settings.targetPath) 149 | } 150 | 151 | for _, value := range project.missingParameters.GetSlice() { 152 | fmt.Println(value) 153 | } 154 | return 155 | } 156 | 157 | if project.incorrectParameters.Length() > 0 { 158 | 159 | fmt.Println("Project generated, but some placeholders in the template were specified with a join character ('[]'), but the given parameter was not a list") 160 | fmt.Println("This may mean you need to specify the following parameters as a comma-separated list") 161 | 162 | for _, value := range project.incorrectParameters.GetSlice() { 163 | fmt.Println(value) 164 | } 165 | } 166 | 167 | // if there's a post-generate script (and it's executable), call it. 168 | err = executePostGenerate(project.rootDirectory, settings.targetPath) 169 | if err != nil { 170 | exitWith("Unable to complete post-generation script: %s\n", err, 1) 171 | return 172 | } 173 | } 174 | 175 | func exitWith(message string, err error, code int) { 176 | 177 | errorMsg := fmt.Sprintf(message, err) 178 | fmt.Fprintf(os.Stderr, errorMsg) 179 | os.Exit(code) 180 | } 181 | -------------------------------------------------------------------------------- /postGenerateScript.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | "path/filepath" 8 | ) 9 | 10 | /* 11 | Checks for the existence of a post-generation script. If it exists (and is executable) 12 | this will execute it, with the working directory set to the generated project. 13 | */ 14 | func executePostGenerate(sourcePath string, generatedPath string) error { 15 | 16 | var command *exec.Cmd 17 | var output []byte 18 | var scriptPath string 19 | var workingDirectory string 20 | var err error 21 | 22 | scriptPath = fmt.Sprintf("%s%s_postGenerate.sh", sourcePath, string(os.PathSeparator)) 23 | scriptPath, err = filepath.Abs(scriptPath) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | generatedPath, err = filepath.Abs(generatedPath) 29 | if err != nil { 30 | return err 31 | } 32 | 33 | // file doesn't exist, exit quietly. 34 | if _, err := os.Stat(scriptPath); os.IsNotExist(err) { 35 | return nil 36 | } 37 | 38 | workingDirectory, err = os.Getwd() 39 | if err != nil { 40 | return err 41 | } 42 | 43 | err = os.Chdir(generatedPath) 44 | if err != nil { 45 | return err 46 | } 47 | defer os.Chdir(workingDirectory) 48 | 49 | command = exec.Command(scriptPath, "") 50 | 51 | output, err = command.CombinedOutput() 52 | if err != nil { 53 | return err 54 | } 55 | 56 | fmt.Printf(string(output)) 57 | 58 | // remove postgenerate script from generated directory. 59 | err = removePostGenerate(generatedPath) 60 | if err != nil { 61 | return err 62 | } 63 | 64 | return nil 65 | } 66 | 67 | func removePostGenerate(generatedPath string) error { 68 | 69 | var scriptPath string 70 | var err error 71 | 72 | scriptPath = fmt.Sprintf("%s%s_postGenerate.sh", generatedPath, string(os.PathSeparator)) 73 | scriptPath, err = filepath.Abs(scriptPath) 74 | if err != nil { 75 | return err 76 | } 77 | 78 | err = os.Remove(scriptPath) 79 | return err 80 | } 81 | -------------------------------------------------------------------------------- /samples/helloworld_chef/README.md: -------------------------------------------------------------------------------- 1 | ${{=cookbook.name=}} 2 | ==== 3 | 4 | A cookbook. 5 | -------------------------------------------------------------------------------- /samples/helloworld_chef/attributes/default.rb: -------------------------------------------------------------------------------- 1 | default[:${{=cookbook.name=}}][:message] = "hello world" 2 | -------------------------------------------------------------------------------- /samples/helloworld_chef/metadata.rb: -------------------------------------------------------------------------------- 1 | name '${{=cookbook.name=}}' 2 | maintainer '${{=cookbook.maintainer=}}' 3 | maintainer_email '${{=cookbook.maintainer_email=}}' 4 | license 'All rights reserved' 5 | description 'A cookbook sample' 6 | long_description IO.read(File.join(File.dirname(__FILE__), "README.md")) 7 | version '1.0.0' 8 | -------------------------------------------------------------------------------- /samples/helloworld_chef/recipes/default.rb: -------------------------------------------------------------------------------- 1 | # Copyright ${{=cookbook.maintainer=}} 2 | # All rights reserved 3 | 4 | Chef::Log.info("Hello, ${{=cookbook.name=}}") 5 | -------------------------------------------------------------------------------- /samples/helloworld_go.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Knetic/wisk/bd3d22952041b8720b9454eee2f54455aed816e1/samples/helloworld_go.zip -------------------------------------------------------------------------------- /samples/helloworld_go/.gitignore: -------------------------------------------------------------------------------- 1 | pkg/ 2 | src/ 3 | ./.output/ 4 | -------------------------------------------------------------------------------- /samples/helloworld_go/README.md: -------------------------------------------------------------------------------- 1 | ${{=project.name=}} 2 | ==== 3 | -------------------------------------------------------------------------------- /samples/helloworld_go/_postGenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git init 4 | git add . --all 5 | git commit -a -m "Initial commit" 6 | -------------------------------------------------------------------------------- /samples/helloworld_go/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export GOPATH="$(pwd)" 4 | 5 | go get ./... 6 | go build -o ./.output/${{=project.name=}} . 7 | -------------------------------------------------------------------------------- /samples/helloworld_go/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | func main() { 8 | 9 | fmt.Printf("Hello, ${{=project.name=}}\n") 10 | } 11 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/.gitignore: -------------------------------------------------------------------------------- 1 | /output/ 2 | /release/ 3 | *.class 4 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/README.md: -------------------------------------------------------------------------------- 1 | # ${{=project.name=}} 2 | 3 | A hello world project, buildable using ant. 4 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/_postGenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git init 4 | git add . --all 5 | git commit -a -m "Initial commit" 6 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Builds ${{=project.name=}} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/lib/README.md: -------------------------------------------------------------------------------- 1 | # ${{=project.name=}} libraries 2 | 3 | All dependencies should be placed in this directory, it will be used during build to package them alongside the main jar. 4 | -------------------------------------------------------------------------------- /samples/helloworld_java_ant/src/${{=project.package[]=}}/Entry.java: -------------------------------------------------------------------------------- 1 | package ${{=project.package[.]=}}; 2 | 3 | public class Entry 4 | { 5 | public static void main(String[] args) 6 | { 7 | System.out.println("Hello, ${{=project.name=}}"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | *.class 3 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/README.md: -------------------------------------------------------------------------------- 1 | # ${{=project.name=}} 2 | 3 | A hello world project, buildable using maven. 4 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/_postGenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git init 4 | git add . --all 5 | git commit -a -m "Initial commit" 6 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 4.0.0 7 | ${{=project.package[.]=}} 8 | ${{=project.name=}} 9 | 10 | ${{=project.name=}} 11 | jar 12 | 1.0-SNAPSHOT 13 | ${{=project.url=}} 14 | 15 | 16 | 17 | junit 18 | junit 19 | 3.8.1 20 | test 21 | 22 | 23 | 24 | 25 | 26 | 27 | org.apache.maven.plugins 28 | maven-jar-plugin 29 | 30 | 31 | src/main/resources/META-INF/MANIFEST.MF 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/src/main/java/${{=project.package[]=}}/Entry.java: -------------------------------------------------------------------------------- 1 | package ${{=project.package[.]=}}; 2 | 3 | public class Entry 4 | { 5 | public static void main(String[] args) 6 | { 7 | System.out.println("Hello, ${{=project.name=}}"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/src/main/resources/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: ${{=project.package[.]=}}.Entry 3 | -------------------------------------------------------------------------------- /samples/helloworld_java_mvn/src/test/${{=project.package[]=}}/EntryTest.java: -------------------------------------------------------------------------------- 1 | package ${{=project.package[.]=}}.tests; 2 | 3 | import ${{=project.package[.]=}}; 4 | import org.junit.Test; 5 | import static org.junit.Assert.assertEquals; 6 | 7 | public class MyTests 8 | { 9 | 10 | @Test 11 | public void shouldRun() 12 | { 13 | Entry.main(null); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/${{=project.name=}}.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require '${{=project.name=}}/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = '${{=project.name=}}' 8 | spec.version = ${{=gem.module[::]=}}::VERSION 9 | spec.authors = ['${{=gem.author=}}'] 10 | spec.email = ['${{=gem.author_email=}}'] 11 | spec.summary = %q{A sample gem} 12 | spec.description = %q{Sample} 13 | spec.homepage = 'http://example.com' 14 | spec.license = 'All rights reserved' 15 | 16 | spec.files = Dir['lib/**/*.rb'] + Dir['bin/*'] + Dir['README.md'] + Dir['docs/**/*'] - Dir['**/*~'] 17 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 18 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 19 | spec.require_paths = ['lib'] 20 | 21 | spec.required_ruby_version = '~> 2.0.0' 22 | 23 | spec.add_development_dependency 'bundler', '~> 1.7' 24 | spec.add_development_dependency 'rspec', '= 3.1.0' 25 | end 26 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/README.md: -------------------------------------------------------------------------------- 1 | ${{=project.name=}} 2 | ==== 3 | 4 | A sample gem. 5 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require '${{=project.name=}}/version' 3 | 4 | task :default => [:build] 5 | 6 | task :build => [:test] do 7 | system("gem build ${{=project.name=}}.gemspec") 8 | end 9 | 10 | task :test => [:prepare] do 11 | system("bundle exec rspec") 12 | end 13 | 14 | task :push => [:build] do 15 | system("gem inabox ./${{=project.name=}}-#{${{=gem.module[::]=}}::VERSION}.gem") 16 | end 17 | 18 | task :prepare do 19 | system("bundle install") 20 | end 21 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/bin/${{=project.name=}}: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require '${{=project.name=}}' 4 | require 'pp' 5 | 6 | pp "Hello, ${{=project.name=}}" 7 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/lib/${{=project.name=}}.rb: -------------------------------------------------------------------------------- 1 | require '${{=project.name=}}/version' 2 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/lib/${{=project.name=}}/core.rb: -------------------------------------------------------------------------------- 1 | require '${{=project.name=}}' 2 | 3 | module ${{=gem.module[::]=}} 4 | 5 | class ${{=gem.class=}} 6 | 7 | def initialize() 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/lib/${{=project.name=}}/version.rb: -------------------------------------------------------------------------------- 1 | require '${{=project.name=}}/version' 2 | 3 | ${{=:gem.module=}} 4 | module ${{value}} 5 | ${{recurse}} 6 | end 7 | ${{=;gem.module=}} 8 | 9 | ${{=gem.module[::]=}}::VERSION = '1.0.0' 10 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/spec/${{=project.name=}}/${{=gem.class=}}_spec.rb: -------------------------------------------------------------------------------- 1 | require '${{=project.name=}}' 2 | 3 | describe '${{=gem.module[::]=}}::${{=gem.class=}}' do 4 | 5 | it 'should work' 6 | end 7 | -------------------------------------------------------------------------------- /samples/helloworld_ruby/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | RSpec.configure do |config| 2 | config.expect_with :rspec do |expectations| 3 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 4 | end 5 | 6 | config.mock_with :rspec do |mocks| 7 | mocks.verify_partial_doubles = true 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /samples/library_python/${{=project.name=}}/${{=class.name=}}.py: -------------------------------------------------------------------------------- 1 | class ${{=class.name=}}(object): 2 | 3 | def __init__(self): 4 | self.exists = True 5 | -------------------------------------------------------------------------------- /samples/library_python/${{=project.name=}}/__init__.py: -------------------------------------------------------------------------------- 1 | from ${{=class.name=}} import ${{=class.name=}} 2 | -------------------------------------------------------------------------------- /samples/library_python/${{=project.name=}}/data/some_data.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Knetic/wisk/bd3d22952041b8720b9454eee2f54455aed816e1/samples/library_python/${{=project.name=}}/data/some_data.html -------------------------------------------------------------------------------- /samples/library_python/${{=project.name=}}/helpers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | if __name__ == "__main__": 5 | import doctest 6 | doctest.testmod(verbose=True) 7 | -------------------------------------------------------------------------------- /samples/library_python/.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | # C extensions 4 | *.so 5 | 6 | # Packages 7 | *.egg 8 | *.egg-info 9 | dist 10 | build 11 | eggs 12 | parts 13 | var 14 | sdist 15 | develop-eggs 16 | .installed.cfg 17 | lib 18 | lib64 19 | 20 | # Installer logs 21 | pip-log.txt 22 | 23 | # Unit test / coverage reports 24 | .coverage 25 | .tox 26 | nosetests.xml 27 | 28 | # Translations 29 | *.mo 30 | 31 | # Mr Developer 32 | .mr.developer.cfg 33 | .project 34 | .pydevproject 35 | -------------------------------------------------------------------------------- /samples/library_python/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 11 | 12 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 15 | 16 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 17 | 18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 19 | 20 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 21 | 22 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 23 | 24 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 25 | 26 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 27 | 28 | The precise terms and conditions for copying, distribution and modification follow. 29 | TERMS AND CONDITIONS 30 | 0. Definitions. 31 | 32 | “This License” refers to version 3 of the GNU General Public License. 33 | 34 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 35 | 36 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 37 | 38 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 39 | 40 | A “covered work” means either the unmodified Program or a work based on the Program. 41 | 42 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 43 | 44 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 45 | 46 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 47 | 1. Source Code. 48 | 49 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 50 | 51 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 52 | 53 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 54 | 55 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 56 | 57 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 58 | 59 | The Corresponding Source for a work in source code form is that same work. 60 | 2. Basic Permissions. 61 | 62 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 63 | 64 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 65 | 66 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 67 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 68 | 69 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 70 | 71 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 72 | 4. Conveying Verbatim Copies. 73 | 74 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 75 | 76 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 77 | 5. Conveying Modified Source Versions. 78 | 79 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 80 | 81 | * a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 82 | * b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 83 | * c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 84 | * d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 85 | 86 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 87 | 6. Conveying Non-Source Forms. 88 | 89 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 90 | 91 | * a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 92 | * b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 93 | * c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 94 | * d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 95 | * e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 96 | 97 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 98 | 99 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 100 | 101 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 102 | 103 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 104 | 105 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 106 | 107 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 108 | 7. Additional Terms. 109 | 110 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 111 | 112 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 113 | 114 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 115 | 116 | * a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 117 | * b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 118 | * c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 119 | * d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 120 | * e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 121 | * f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 122 | 123 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 124 | 125 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 126 | 127 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 128 | 8. Termination. 129 | 130 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 131 | 132 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 133 | 134 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 135 | 136 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 137 | 9. Acceptance Not Required for Having Copies. 138 | 139 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 140 | 10. Automatic Licensing of Downstream Recipients. 141 | 142 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 143 | 144 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 145 | 146 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 147 | 11. Patents. 148 | 149 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 150 | 151 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 152 | 153 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 154 | 155 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 156 | 157 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 158 | 159 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 160 | 161 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 162 | 163 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 164 | 12. No Surrender of Others' Freedom. 165 | 166 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 167 | 13. Use with the GNU Affero General Public License. 168 | 169 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 170 | 14. Revised Versions of this License. 171 | 172 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 173 | 174 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 175 | 176 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 177 | 178 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 179 | 15. Disclaimer of Warranty. 180 | 181 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 182 | 16. Limitation of Liability. 183 | 184 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 185 | 17. Interpretation of Sections 15 and 16. 186 | 187 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 188 | 189 | END OF TERMS AND CONDITIONS 190 | -------------------------------------------------------------------------------- /samples/library_python/Makefile: -------------------------------------------------------------------------------- 1 | PYTHON=`which python` 2 | NAME=`python setup.py --name` 3 | VERSION=`python setup.py --version` 4 | SDIST=dist/$(NAME)-$(VERSION).tar.gz 5 | VENV=/tmp/venv 6 | 7 | 8 | all: check test source deb 9 | 10 | dist: source deb 11 | 12 | source: 13 | $(PYTHON) setup.py sdist 14 | 15 | deb: 16 | $(PYTHON) setup.py --command-packages=stdeb.command bdist_deb 17 | 18 | rpm: 19 | $(PYTHON) setup.py bdist_rpm --post-install=rpm/postinstall --pre-uninstall=rpm/preuninstall 20 | 21 | install: 22 | $(PYTHON) setup.py install --install-layout=deb 23 | 24 | test: 25 | unit2 discover -s tests -t . 26 | 27 | check: 28 | find . -name \*.py | grep -v "^test_" | xargs pylint --errors-only --reports=n 29 | # pep8 30 | # pyntch 31 | # pyflakes 32 | # pychecker 33 | # pymetrics 34 | 35 | upload: 36 | $(PYTHON) setup.py sdist register upload 37 | $(PYTHON) setup.py bdist_wininst upload 38 | 39 | init: 40 | pip install -r requirements.txt --use-mirrors 41 | 42 | update: 43 | rm ez_setup.py 44 | wget http://peak.telecommunity.com/dist/ez_setup.py 45 | 46 | daily: 47 | $(PYTHON) setup.py bdist egg_info --tag-date 48 | 49 | deploy: 50 | # make sdist 51 | rm -rf dist 52 | python setup.py sdist 53 | 54 | # setup venv 55 | rm -rf $(VENV) 56 | virtualenv --no-site-packages $(VENV) 57 | $(VENV)/bin/pip install $(SDIST) 58 | 59 | clean: 60 | $(PYTHON) setup.py clean 61 | rm -rf build/ MANIFEST dist build ${{=project.name=}}.egg-info deb_dist 62 | find . -name '*.pyc' -delete 63 | -------------------------------------------------------------------------------- /samples/library_python/README.md: -------------------------------------------------------------------------------- 1 | ${{=project.name=}} 2 | ==== 3 | 4 | A python library. 5 | -------------------------------------------------------------------------------- /samples/library_python/_postGenerate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git init 4 | git add . --all 5 | git commit -a -m "Initial commit" 6 | -------------------------------------------------------------------------------- /samples/library_python/bin/${{=project.name=}}: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from ${{=project.name=}} import main 4 | 5 | main() 6 | -------------------------------------------------------------------------------- /samples/library_python/docs/doc.txt: -------------------------------------------------------------------------------- 1 | # use Pandoc’s Markdown: http://www.johnmacfarlane.net/pandoc/ 2 | # or use reStructuredText markup: http://docutils.sourceforge.net/rst.html 3 | 4 | -------------------------------------------------------------------------------- /samples/library_python/requirements-dev.txt: -------------------------------------------------------------------------------- 1 | python-stdeb 2 | python-unittest2 3 | fakeroot 4 | python-all 5 | -------------------------------------------------------------------------------- /samples/library_python/requirements.txt: -------------------------------------------------------------------------------- 1 | setuptools 2 | -------------------------------------------------------------------------------- /samples/library_python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | from setuptools import setup, find_packages 5 | 6 | 7 | setup(name='${{=project.name=}}', 8 | version='0.0.1', 9 | author='${{=project.author=}}', 10 | author_email='${{=project.author_email=}}', 11 | url='http://www.${{=project.url=}}', 12 | download_url='http://www.${{=project.name=}}/files/', 13 | description='Short description of ${{=project.name=}}...', 14 | long_description='Short description of ${{=project.name=}}...', 15 | 16 | packages = find_packages(), 17 | include_package_data = True, 18 | package_data = { 19 | '': ['*.txt', '*.rst'], 20 | '${{=project.name=}}': ['data/*.html', 'data/*.css'], 21 | }, 22 | exclude_package_data = { '': ['README.txt'] }, 23 | 24 | scripts = ['bin/${{=project.name=}}'], 25 | 26 | keywords='python tools utils internet www', 27 | license='GPL', 28 | classifiers=['Development Status :: 5 - Production/Stable', 29 | 'Natural Language :: English', 30 | 'Operating System :: OS Independent', 31 | 'Programming Language :: Python :: 2', 32 | 'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)', 33 | 'License :: OSI Approved :: GNU Affero General Public License v3', 34 | 'Topic :: Internet', 35 | 'Topic :: Internet :: WWW/HTTP', 36 | ], 37 | 38 | #setup_requires = ['python-stdeb', 'fakeroot', 'python-all'], 39 | install_requires = ['setuptools'], 40 | ) 41 | -------------------------------------------------------------------------------- /samples/library_python/tests/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Knetic/wisk/bd3d22952041b8720b9454eee2f54455aed816e1/samples/library_python/tests/__init__.py -------------------------------------------------------------------------------- /samples/library_python/tests/test_helpers.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding=utf-8 3 | 4 | import unittest 5 | 6 | from ${{=project.name=}} import ${{=class.name=}} 7 | 8 | 9 | class Test(unittest.TestCase): 10 | """Unit tests for ${{=project.name=}}.${{=class.name=}}""" 11 | 12 | def test_fn(self): 13 | """Test result""" 14 | instance = ${{=class.name=}}() 15 | value = True 16 | result = instance.exists 17 | self.assertEqual(value, result) 18 | 19 | if __name__ == "__main__": 20 | unittest.main() 21 | --------------------------------------------------------------------------------