workEnv 0.1.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.
@@ -0,0 +1,49 @@
1
+ module WorkEnvs
2
+ class AnyEnv < BasicEnv
3
+ MAIN_PACKAGE = "Any"
4
+ ENV_TYPE = :any
5
+ ENV_DESCRIPTION = "Any Combination of environments"
6
+ PARENTS = ENV_LIST.map(){|x|
7
+ if x == "Any" || x == "Work" then
8
+ nil
9
+ else
10
+ WorkEnvs.const_get(x + "Env")
11
+ end
12
+ }.compact()
13
+ PACKAGES = {
14
+ :external => {
15
+ :required => [],
16
+ :extras => [],
17
+ },
18
+ :internal => {
19
+ :required => [],
20
+ :extras => [],
21
+ },
22
+ :temporary => {
23
+ :required => [],
24
+ :extras => [],
25
+ }
26
+ }
27
+ DEPENDENCIES = {},
28
+ OPTIONS = []
29
+ REV_FILE = 'any_revision'
30
+ GIT_REPO = 'git:software/foo/bar'
31
+
32
+ def initialize(name, machine, release)
33
+ super(name, machine, release)
34
+ @versions[ENV_TYPE] = :uninitialized
35
+ @type = ENV_TYPE
36
+ end
37
+
38
+ def self.getVersion(path, canFail = false)
39
+ versions[:any] = "any"
40
+ return versions
41
+ end
42
+
43
+ def self.post_setup(opts = {})
44
+ end
45
+ def self.switchEnv(env, path)
46
+ return []
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,204 @@
1
+ module WorkEnvs
2
+ # Default Env class
3
+ # All environment should inherit from this.
4
+ #
5
+ #
6
+ # They must provide these constants:
7
+ # * MAIN_PACKAGE
8
+ # * ENV_TYPE
9
+ # * ENV_DESCRIPTION
10
+ # * PARENTS
11
+ # * PACKAGES
12
+ # * DEPENDENCIES
13
+ # * OPTIONS
14
+ # * REV_FILE
15
+ # * GIT_REPO
16
+ class BasicEnv < Core
17
+ # Name of the package used to lookup the environment in the DB
18
+ MAIN_PACKAGE = ""
19
+
20
+ # Unique label to describe the env Class
21
+ ENV_TYPE = :dev
22
+
23
+ # String to describethe env in man pages/help
24
+ ENV_DESCRIPTION = "Empty environment"
25
+
26
+ # Array of parent Classes
27
+ #
28
+ # Parent classes (also called sub classed) are env Classes that are used by this Env
29
+ #
30
+ # When updating an env they should usually be downloaded and extracted to.
31
+ # Their dependency come either from:
32
+ # - Integration stuff (rev_files, manual --sub-sha1 opts)
33
+ # - More genrally through packages (RPM/Deb) dependencies as described in #DEPENDENCIES
34
+ PARENTS = []
35
+
36
+ # List of all the packages provided by this envClass
37
+ #
38
+ # Three top levels to the hash:
39
+ # - :external: Package that should end up in the release packages
40
+ # - :internal: Internal build packages. Do not deliver
41
+ # - :temporary: Package needed during the setup pahe but to be removed afterward
42
+ # Specially used for keygens
43
+ # Two bottom levels:
44
+ # - :required: package MUST be available or there is an issue
45
+ # - :extras: package are retreive if available
46
+ # This used for package that are added as time passes but are not available
47
+ # for all versions
48
+ PACKAGES = {
49
+ :external => {
50
+ :required => [],
51
+ :extras => [],
52
+ },
53
+ :internal => {
54
+ :required => [],
55
+ :extras => [],
56
+ },
57
+ :temporary => {
58
+ :required => [],
59
+ :extras => [],
60
+ }
61
+ }
62
+
63
+ # Dependency descriptor used to extract dependencies to parent envClass from packages
64
+ #
65
+ # Format of the hash is
66
+ # regexp => { [ env types ] => [ package name to match ]
67
+ #
68
+ # - The regexp is matched on the packages listed by this env class
69
+ # - The env types allows to point to a specific env if a package name
70
+ # belong to multiple env Class
71
+ # - Package name that may or may not be the MAIN_PACKAGE of parent Classes
72
+ DEPENDENCIES = {
73
+ }
74
+
75
+ # Array of env specific options help string
76
+ OPTIONS = [
77
+ WENV_OPTS_EXTERNAL_STRING, WENV_OPTS_PARTIAL_STRING, WENV_OPTS_CONST_STRING
78
+ ]
79
+ # Revision file name. Should end with __revision
80
+ REV_FILE = 'n/a'
81
+
82
+ # Repository path
83
+ # This is used to find "siblings" env classes (meaning different packages but same SHA1)
84
+ GIT_REPO = ''
85
+
86
+ # Name of the environment
87
+ attr_accessor :name
88
+ # ENV_TYPE of the appropriate env Class
89
+ attr_accessor :type
90
+ # Version stored during update by getVersion functions
91
+ attr_accessor :versions
92
+ # Dependencies Object generated during update
93
+ attr_accessor :deps_infos
94
+ # Optional expiration date for licenses
95
+ attr_accessor :expiration
96
+ # EnvOpts Object geenrated during update
97
+ attr_accessor :setup_options
98
+ # Target architecture String
99
+ attr_accessor :machine
100
+ # DB Tables used
101
+ attr_accessor :db_tables
102
+ # Internal Core versio number for migration
103
+ attr_accessor :version
104
+ # Hash to store custom properties
105
+ attr_accessor :properties
106
+ # Magic flag to ignore conflict during update (stored for --copy-env)
107
+ attr_accessor :ignore_conflicts
108
+ # Label describing which dir the env is stored to
109
+ # Cleared on dump to avoid messing with other setups
110
+ attr_accessor :label
111
+
112
+ # Subclass should implement this, start by calling super, fix their type and initialize theuir version to
113
+ # :unitialized
114
+ def initialize(name, machine, release)
115
+ if ! WorkEnvs::isValidName?(name)
116
+ raise("Invalid name '#{name}' for an environment. Syntax is [a-zA-Z0-9][a-zA-Z0-9_.-]*")
117
+ end
118
+
119
+ arch = WorkEnvs::getArch(machine)
120
+ @name = name
121
+ @type = ENV_TYPE
122
+ @machine = arch[:label]
123
+ @versions={}
124
+ @deps_infos = nil
125
+ @expiration = " N/A "
126
+ @db_tables = DBInterface::toTable(release)
127
+ @setup_options = EnvOpts.new();
128
+ @version = WORK_ENV_VERSION
129
+ @properties = {}
130
+ @parents = []
131
+ @ignore_conflicts = false
132
+ end
133
+
134
+ # This returns a map that contains the environment version and all the
135
+ # version of the inherited environments as versions[:'type'] = 'version id'
136
+ def self.getVersion(path, canFail = false)
137
+ versions = {}
138
+ return versions
139
+ end
140
+
141
+ # Function called by update during env cleanup
142
+ def self.cleanup(opts)
143
+ end
144
+
145
+ # Function called during pre-setup, before download
146
+ #
147
+ # These functions are allowed to modify the package lists
148
+ def self.pre_setup(opts, packages, temp_packages)
149
+ end
150
+
151
+ # Post install script. This is called after all definitive and temporary packages are downloaded
152
+ # It is called from the temporary package directory
153
+ # opts define :tempDir with the current directory and :dir for the install directory
154
+ # This must call super before or after its own role to make sure inherited environments are initialized
155
+ def self.post_setup(opts = {})
156
+ return if self != WorkEnvs::BasicEnv
157
+ path = opts[:dir]
158
+ runCmd("mkdir -p #{path}/kEnv-config", !VERBOSE)
159
+
160
+ end
161
+
162
+ # Function called after download and extract but before installation of system packages
163
+ def self.pre_install(opts, packages, temp_packages)
164
+ end
165
+
166
+ # Function called after installation of system packages
167
+ def self.post_install(opts, packages, temp_packages)
168
+ end
169
+
170
+ # Function to generate commands into the switch env script for this env class
171
+ #
172
+ # Returns an array of string
173
+ def self.switchEnv(env, path)
174
+ return [] if self != WorkEnvs::BasicEnv
175
+
176
+ array=[]
177
+ array << "#!/bin/bash"
178
+ array << ""
179
+ array << "unset BASH_ENV"
180
+ array << "export WORK_ENV_SCRIPTS_DIR=\"#{WORK_ENV_SCRIPTS_DIR}\""
181
+ array << "export WORK_ENVS=\"$(dirname $(dirname $( readlink -f $BASH_SOURCE)))\""
182
+ array << "export WORK_ENV_CURRENT=\"$(basename $(dirname $( readlink -f $BASH_SOURCE)))\""
183
+ array << "export WORK_ENV_PATH=\"${WORK_ENVS:-/work1/$(whoami)/work-envs}/${WORK_ENV_CURRENT}\""
184
+ array << "export WORK_ENV_CURRENT_TYPE=#{env.type.to_s}"
185
+ array << "export WORK_ENV_LOADING_BASHRC='y'"
186
+ array << "[ -z $WORK_ENV_NOBASHRC ] && [ -f ~/.bashrc ] && . ~/.bashrc"
187
+ array << "unset WORK_ENV_LOADING_BASHRC"
188
+ array << ""
189
+ array << "export PATH=\"${WORK_ENV_SCRIPTS_DIR}${PATH:+:$PATH}\""
190
+ array << "export MANPATH=\"${WORK_ENV_SCRIPTS_DIR}/man:${MANPATH}\""
191
+ array << "export WORK_ENV_PS1=\"${WORK_ENV_CUSTOM_COLOR_START}${WORK_ENV_CURRENT:+($WORK_ENV_CURRENT) }"+
192
+ "${WORK_ENV_CUSTOM_COLOR_STOP}\""
193
+ array << "export PS1=\"${WORK_ENV_PS1}${PS1}\""
194
+ return array
195
+ end
196
+
197
+ # Returns if an environment is of dev type
198
+ def self.isDev?()
199
+ type_str = WorkEnvs::getEnvType(self).to_s
200
+ return true if type_str =~ /^dev/
201
+ return false
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,147 @@
1
+ module WorkEnvs
2
+ # Take an env object or an envClass as an input and return the env Class
3
+ def envToClass(env)
4
+ return env if env.kind_of? Class
5
+ return env.class
6
+ end
7
+ module_function :envToClass
8
+
9
+ # Get the MAIN_PACKAGE from an env or an envClass
10
+ #
11
+ # Return an array of package Strings
12
+ #
13
+ # Throws an exception is MAIN_PACKAGE is not set
14
+ def getMainPackage(env, version=0)
15
+ envClass = WorkEnvs::envToClass(env)
16
+ begin
17
+ mainPack = envClass.const_get(:MAIN_PACKAGE)
18
+ return mainPack if mainPack.kind_of?(Array)
19
+ return [ mainPack ]
20
+ rescue
21
+ raise("Environment class #{envClass} has no 'MAIN_PACKAGE'")
22
+ end
23
+ end
24
+ module_function :getMainPackage
25
+
26
+ # Get the ENV_TYPE from an env or an envClass
27
+ #
28
+ # Return a label or nil if ENV_TYPE is not set
29
+ def getEnvType(env)
30
+ envClass = WorkEnvs::envToClass(env)
31
+ begin
32
+ return envClass.const_get(:ENV_TYPE)
33
+ rescue
34
+ return nil
35
+ end
36
+ end
37
+ module_function :getEnvType
38
+
39
+
40
+ # Get the PACKAGES hash from an env or an envClass
41
+ #
42
+ # Return a hash of hash of packages
43
+ #
44
+ # Throws an exception is PACKAGES is not set
45
+ def getPackages(env, version=0)
46
+ envClass = WorkEnvs::envToClass(env)
47
+ begin
48
+ return envClass.const_get(:PACKAGES)
49
+ rescue
50
+ raise("Environment class #{envClass} has no 'PACKAGES'")
51
+ end
52
+ end
53
+ module_function :getPackages
54
+
55
+ # Get the DEPENDENCIES from an env or an envClass
56
+ #
57
+ # Return a hash of dependencies or {} if DEPENDENCIES is not set
58
+ def getDependencies(env, version=0)
59
+ envClass = WorkEnvs::envToClass(env)
60
+ begin
61
+ return envClass.const_get(:DEPENDENCIES)
62
+ rescue
63
+ return {}
64
+ end
65
+ end
66
+ module_function :getDependencies
67
+
68
+ # Get the GIT_REPO from an env or an envClass
69
+ #
70
+ # Return a String "" if GIT_REPO is not set
71
+ def getGitRepo(env, version=0)
72
+ envClass = WorkEnvs::envToClass(env)
73
+ begin
74
+ return envClass.const_get(:GIT_REPO)
75
+ rescue
76
+ return ""
77
+ end
78
+ end
79
+ module_function :getGitRepo
80
+
81
+ # Get the REV_FILE from an env or an envClass
82
+ #
83
+ # Return a String or "n/a" if REV_FILE is not set
84
+ def getRevFile(env, version=0)
85
+ envClass = WorkEnvs::envToClass(env)
86
+ begin
87
+ return envClass.const_get(:REV_FILE)
88
+ rescue
89
+ return "n/a"
90
+ end
91
+ end
92
+ module_function :getRevFile
93
+
94
+
95
+ # Get the ENV_DESCRIPTION from an env or an envClass
96
+ #
97
+ # Return a String with the env description
98
+ def getEnvDescription(env, version=0)
99
+ envClass = WorkEnvs::envToClass(env)
100
+ begin
101
+ return envClass.const_get(:ENV_DESCRIPTION)
102
+ rescue
103
+ return "<No description provided>"
104
+ end
105
+ end
106
+ module_function :getEnvDescription
107
+
108
+ # Get the PARENTS from an env or an envClass
109
+ #
110
+ # Return an of parent env Classes or [] if PARENTS is not set
111
+ def getParents(env, version=0)
112
+ envClass = WorkEnvs::envToClass(env)
113
+ begin
114
+ return envClass.const_get(:PARENTS)
115
+ rescue
116
+ return []
117
+ end
118
+ end
119
+ module_function :getParents
120
+
121
+ # Get the OPTIONS from an env or an envClass
122
+ #
123
+ # Return an array of options help strings or [] if OPTIONS is not set
124
+ def getOptions(env, version=0)
125
+ envClass = WorkEnvs::envToClass(env)
126
+ begin
127
+ return envClass.const_get(:OPTIONS)
128
+ rescue
129
+ return []
130
+ end
131
+ end
132
+ module_function :getOptions
133
+
134
+
135
+ # Get the BLACKLIST from an env or an envClass
136
+ #
137
+ # Return an array of blacklisted packages or [] if BLACKLIST is not set
138
+ def getBlackList(env, version=0)
139
+ envClass = WorkEnvs::envToClass(env)
140
+ begin
141
+ return envClass.const_get(:BLACKLIST)
142
+ rescue
143
+ return []
144
+ end
145
+ end
146
+ module_function :getBlackList
147
+ end