python-generator 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/python-generator +4 -0
  3. data/lib/generator.rb +103 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f3624d97f8e0e661cf80cad081f55fa61222e79e4b345741ca5e4eb53fc6bac8
4
+ data.tar.gz: 716294baea70460743e9546c325e2f0ca94f7d7f3a4439f0faa81d4c77751671
5
+ SHA512:
6
+ metadata.gz: c506ce2ff67658db67a97bbaa6fd462f0741ebf9e5f9d6ce3e497810a38ee311c6fa2c25eb9863c7686a2822a8e6623c01acc251b7dca5760f8cc6ab79b0c8de
7
+ data.tar.gz: b8af9fc1b8001ac5e75f86a7414a8f8e92dec6f14c470525f697c13a8f9af9d5af4dad20aa5da5734420a21f83384cecb431c151dc472e512e1b0f89c0479515
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/generator'
3
+
4
+ Generator.new.run(ARGV)
data/lib/generator.rb ADDED
@@ -0,0 +1,103 @@
1
+ require 'pry'
2
+ class Generator
3
+ attr_accessor :pdir, :executable, :environment, :project, :requirements
4
+
5
+ GREEN='\033[0;32m'
6
+ RED='\033[0;31m'
7
+ NC='\033[0m'
8
+ CREATED = "#{GREEN}created#{NC}"
9
+ ADDLINE = "#{GREEN}added#{NC}"
10
+ ERROR = "#{RED}Error#{NC}: "
11
+
12
+ def run(array)
13
+ if array[0] == "new"
14
+ # binding.pry
15
+ array.length < 3 ? new(array[1]) : new(array[1], array[2..(array.length-1)])
16
+ elsif array[0] == "--help"
17
+ help
18
+ else
19
+ error("unknown command")
20
+ end
21
+ end
22
+
23
+ def error(error_text)
24
+ system("printf '#{ERROR} #{GREEN}#{error_text}#{NC}\n'")
25
+ system("printf 'type #{GREEN}ruby-generator --help#{NC} for more options\n'")
26
+ end
27
+
28
+ def new(project, dependencies=nil)
29
+ # print "What would you like to call your project? "
30
+ # project = gets.strip
31
+ @project = project
32
+ @pdir = "./#{project}"
33
+ @executable = "#{pdir}/bin/#{project}"
34
+ @environment = "#{project}/config/environment.py"
35
+ @requirements = "#{pdir}/requirements.txt"
36
+ create_project_dir
37
+ add_bin
38
+ add_config
39
+ add_lib
40
+ !dependencies ? add_requirements : add_requirements(dependencies)
41
+ end
42
+
43
+ def create_project_dir
44
+ add_folder(pdir)
45
+ end
46
+
47
+ def add_bin
48
+ add_folder("#{pdir}/bin")
49
+ add_file("#{pdir}/bin/#{project}")
50
+ add_line("#!usr/bin/env python", executable)
51
+ add_line("\nimport os", executable)
52
+ add_line("import sys", executable)
53
+ add_line("\ncwd = os.getcwd()", executable)
54
+ add_line('sys.path.append(cwd + "/config")', executable)
55
+ add_line("\nfrom config import *", executable)
56
+ end
57
+
58
+ def add_requirements(dependencies=nil)
59
+ add_file("#{pdir}/requirements.txt")
60
+ if dependencies
61
+ dependencies.each do |d|
62
+ add_line(d, requirements)
63
+ end
64
+ end
65
+ end
66
+
67
+ def add_lib
68
+ add_folder("#{pdir}/lib")
69
+ end
70
+
71
+ def add_config
72
+ add_folder("#{pdir}/config")
73
+ add_file(environment)
74
+ add_line("import os", environment)
75
+ add_line("import sys", environment)
76
+ add_line("\ncwd = os.getcwd()", environment)
77
+ add_line('sys.path.append(cwd + "/lib")', environment)
78
+ add_line("\nfrom lib import *", environment)
79
+ end
80
+
81
+ def add_file(path)
82
+ system("touch #{path}")
83
+ system("printf '#{CREATED} #{path}\n'")
84
+ end
85
+
86
+ def add_folder(path)
87
+ system("mkdir #{path}")
88
+ system("printf '#{CREATED} #{path}\n'")
89
+ end
90
+
91
+ def add_line(text, path)
92
+ system("echo '#{text}' >> #{path}")
93
+ system("printf '#{ADDLINE} #{text} >> #{path}\n'")
94
+ end
95
+
96
+
97
+ def help
98
+ system("printf '\n#{GREEN}Python Generator Commands#{NC}\n'")
99
+ system("printf -- '-----------------------\n'")
100
+ system("printf '#{RED}new <project name> <dependencies(optional)>#{NC} - Creates a new python project.\n\n'")
101
+ end
102
+
103
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: python-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Enoch Griffith
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem that helps you quickly build a python project
14
+ email: enochgriffith1985@gmail.com
15
+ executables:
16
+ - python-generator
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/python-generator
21
+ - lib/generator.rb
22
+ homepage:
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.7.6
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A Python Project Generator
45
+ test_files: []