Create a coffeescript to access config.ini file - coffeescript

i am trying to use config.ini in an existing coffeescript.
this is my config.ini
[env]
RUNNING_ENV = 'dev'
[dev]
security="no"
priority="P2"
[prod]
security="yes"
priority="P1"
Please assist me on creating a coffee file which can read these config data . I am a python deeveloper and i am new to coffee script

config.ini aren't usually used in node projects.
There are packages (like ini-config) which can parse a config.ini file and make it's values accessible in your code.
Instead I would just use environment variables which are automatically accessible under process.env in a node (in this case written in coffeescript) project.
You might like to use the dot-env package which is a common way of organising environment variables. Here is a good blog post on the topic.

Related

Catalyst Log4perl: configure config file location from app config

In a Catalyst app, I need to specify the Log4perl's config file location. All the examples I could find suggest that I should do that from code. However, I would like to be able to specify it in the app config file. This would allow me to use different log configs for different environments and manage all that from a single file. I would also like to be able to set log levels from app config file.
However, there seems to be no documented way of configuring the logger from the app config file. I tried multiple variations of syntax, but none was picked up by Catalyst. It is also impossible to set the correct config file name from MyApp.pm (main app module), as configuration is not yet available when module code is run.
Debugging the logger initialization code also didn't help. The only real way I am considering now is to require a config file from MyApp.pm, which would include the necessary configuration.
The questions thus are:
Is there a way to specify the Log4perl config file location from Catalyst config file?
Is there a way to specify log levels from a config file?
I thought I'd googled enough, but apparently I hadn't.
__PACKAGE__->setup();
__PACKAGE__->log(Log::Log4perl::Catalyst->new(__PACKAGE__->path_to(__PACKAGE__->config->{Log}->{config_file})->stringify));
(ref http://www.gossamer-threads.com/lists/catalyst/users/31271).
And as for log levels: they are defined in the actual Log4perl config file.

Customizing buildbot webstatus

I'm trying customizing the webstatus templates for my buildbot 0.8.8 installation
According to the documentation:
Buildbot uses a templating system for the web interface. The source of these templates can be found in the status/web/templates/ directory in buildbot's library area. You can override these templates by creating alternate versions in a templates/ directory within the buildmaster's base directory.
Here what I did:
copied all html templates from my buildbot installation folder (/usr/lib64/.../status/web/templates) into the templates folder I found inside my buildmaster installation root folder (the templates was already there, and it contains a README file that seems to confirm what the documentation states)
modified the root.html templates
Unfortunately I cannot see any changes in the webstatus page.
Another test I did is to directly change the original template file in the buildbot installation path. The changes are now displayed. It seems like the buildmaster is not "seeing" the new template in the local configuration path.
I checked the file/dir permissions and I cannot spot any issue on that side.
Tried cleaning up the browser cache without luck as well.
Have I done something wrong?
As per source code, templates are retrieved from the WebStatus objects, i.e.
builder.py:573 ([1]) :
template = req.site.buildbot_service.templates.get_template("builders.html")
This property is created in baseweb.py:465 ([2]) :
self.templates = createJinjaEnv(revlink, self.changecommentlink,
self.repositories, self.projects, self.jinja_loaders)
The template lookup algorithm can be found in createJinjaEnv function, around base.py:506 ([3]) :
all_loaders = [jinja2.FileSystemLoader(os.path.join(os.getcwd(), 'templates'))]
if jinja_loaders:
all_loaders.extend(jinja_loaders)
all_loaders.append(jinja2.PackageLoader('buildbot.status.web', 'templates'))
loader = jinja2.ChoiceLoader(all_loaders)
As per documentation [4], jinja will return the first existing file in specified list, so while trying to load your template, Jinja will lookup sequentially in :
cwd
jinja_loaders property, that can be defined in WebStatus constructor by jinja_loaders param in your master.cfg
files from python package
IMO the easiest option is the second.
Hope it helps
[1]https://github.com/buildbot/buildbot/blob/2ab0e16ed0c46249f1d33308fd6878a1fc953f6e/master/buildbot/status/web/builder.py#L573
[2]https://github.com/buildbot/buildbot/blob/2ab0e16ed0c46249f1d33308fd6878a1fc953f6e/master/buildbot/status/web/baseweb.py#L465
[3]https://github.com/buildbot/buildbot/blob/2ab0e16ed0c46249f1d33308fd6878a1fc953f6e/master/buildbot/status/web/base.py#L506
[4]http://jinja.pocoo.org/docs/dev/api/#jinja2.ChoiceLoader

Environment specific config in Play framework application

I've had a look around but it's not very clear to me how I can configure a set of environment specific variables for my Play framework application.
As an example, I would like to use an in memory database like h2 for local development but when I move to production or my pre-production environment I would like to be connecting to a postgres database.
How do I configure my app so that it will use the variables relevant to the environment it is being deployed to? This is a Scala Play app.
One option (as documented in the excellent play docs), is to specify conf files during app startup.
Using -Dconfig.resource will search for an alternative configuration file in the application classpath (you usually provide these alternative configuration files into your application conf/ directory before packaging). Play will look into conf/ so you don’t have to add conf/.
$ /path/to/bin/<project-name> -Dconfig.resource=prod.conf
Using -Dconfig.file you can specify an environment specific configuration file not packaged into the application artifacts:
$ start -Dconfig.file=/opt/conf/prod.conf
Using -Dconfig.url you can also specify a configuration file to be loaded from any URL:
$ start -Dconfig.url=http://conf.mycompany.com/conf/prod.conf
Note that you can always reference the original configuration file in a new prod.conf file using the include directive, such as:
include "application.conf"
key.to.override=blah
You can have Puppet or some similar tools to generate the needed parameters in environment.conf and place in a dedicated directory.
Then in application.conf, at the end of the file, have this:
include "file:///[your directory...]/environment.conf"
to override any testing or local values (e.g.DB parameteres) listed above
You can use different configuration files by overriding onLoadConfig method of the Global object like:
object Global extends GlobalSettings {
override def onLoadConfig(config: Configuration, path: File, classloader: ClassLoader, mode: Mode.Mode): Configuration = {
val fileName = s"application.${mode.toString.toLowerCase}.conf"
config ++ Configuration(ConfigFactory.load(fileName))
}
}
This way you have 'application.test.conf' for test mode and 'application.dev.conf' for develop mode whereas you can use another config file in production via '-Dconfig.file' parameter.

Configuration centralization for Play2 Scala; or how to stop hardcoding variables

At the moment, I'm hardcoding several variables like resource names and ports. I would like to move them out of my code.
What are recommended means of implementing a central configuration outside the actual code? Like a file maybe. So that, while the production and development are using same git repository, the configurations would be seperate. I am using Play 2 Framework on Scala.
I would suggest using the Typesafe Config library. It loads and parses files that can be a mix of .properties style, JSON, or extended JSON (called HOCON - "Human-Optimized Config Object Notation"), and is the configuration style used by Play 2 itself (and Akka, Spray, and a quickly growing list of other libraries).
In Play's standard application.conf file you can include files like so:
include "file:///..."
In this file you could override what properties you need to.
Additionally, (as documented in the excellent play docs), one can specify conf files during app startup like so:
Using -Dconfig.file
You can also specify another local configuration file not packaged into the application artifacts:
$ start -Dconfig.file=/opt/conf/prod.conf
Using -Dconfig.url
You can also specify a configuration file to be loaded from any URL:
$ start -Dconfig.url=http://conf.mycompany.com/conf/prod.conf
Note that you can always reference the original configuration file in a new prod.conf file using the include directive, such as:
include "application.conf"
key.to.override=blah
Configuration is likely a mean of taste, but Typesafe Config is one of the common libraries to use in scala/play ecosystem (e.g. it is used in akka).

Do Doxygen config files support variables?

For instance I set the source code path as c:\code\testapp\src. Is this then available as a var I can use - for instance so I can spit out a tag file in a location relative to this, not relative to the working dir of doxygen? I think I'm looking for something like how Ant defines vars for just about everything and these can be re-used; does Doxygen have special vars for any of the config values?
I'm thinking like $PROJECT-NAME or %VERSION% or whatever...
You can use environment variables in the configuration file; the syntax is the same as in a makefile, i.e. $(VAR_NAME)
I am not sure, but I have seen people use variables as part of their build process. For example the lemon graph library uses cmake, sets a variable for the absolute file path in cmake and the doxygen config file includes variables such as #abs_top_srcdir#. Through the build process these variables are replaced with the relevant text.