Create custom puppet fact as target of link? - puppet

Looking for how to get the target of a symlink as a custom puppet fact via facter. How would I complete this:
Facter.add(:link_target) do
setcode do
...
end
end

It's not obvious why you would want to do this, but assuming you already know the source file and it is constant then all you would need is:
Facter.add(:foo_link_target) do
setcode 'readlink /path/to/foo'
end
If that doesn't help, you are best to fix the question so we know what you are trying to achieve.

Related

Recommended way to achieve `rescue-ensure` kind of functionality with Kiba?

We have a Kiba pipeline where we need to do some task after the job has ended, no matter if there were errors or not (the whole pipeline doesn't fail, we just have couple of validation errors or similar).
This is what the documentation says:
:warning: Post-processors won't get called if an error occurred before them.
https://github.com/thbar/kiba/wiki/Implementing-pre-and-post-processors
Would this be recommended way to do this:
Kiba.run(
Kiba.parse do
source(...)
transform(...)
destination(....)
post_process do
# we cannot do it here, because it won't get called
end
end
)
# is this the location to do it?
Job.some_special_cleanup_task
Thanks!
PS what does it mean:
Post-processors won't get called if an error occurred before them.
Does this mean if the error occurred and wasn't rescued from?
Indeed post_process will not be called in case of errors, as documented and as you pointed out!
At this point, the best solution is to use a form of ensure statement:
A common way to structure that is:
module ETL
module Job
module_function
def setup(config)
Kiba.parse do
source(...)
transform(...)
destination(....)
end
end
def some_special_cleanup_task
# ...
end
def run(job)
Kiba.run(job)
ensure
Job.some_special_cleanup_task
end
end
end
Doing so allows to keep the code for the always-run task close to the ETL job, which is nice.
If your task is instead very independent from the job, and you want to encourage reuse between jobs, you can also create a generic block-form component:
module ETL
module Middlewares
module CommonTask
module_function
def with_common_task
yield
ensure
do_the_common_task
end
end
end
end
Which you would use like this:
ETL::Middlewares::CommonTask.with_common_task do
Kiba.run(...)
end
This second form is used by Kiba Pro FileLock, for instance.
In the future, Kiba ETL will introduce a form of middleware to make this even easier.
Hope this helps, and please mark the question as answered if it properly solves your problem!

Base folder in directory structure

So I'm fairly new to UNIX (This might be basic but I couldn't find a good answer) and I'm trying to run some code I got from the web. In the README it says:
"If you put these 3rd-party packages in a pathUtils folder in the same base
folder as the shadowDetection, they should be picked up automatically by
setPath. "
Does this mean I need to create a pathUtils folder in the same directory as shadowDetection? So it would look like:
/path/shadowDetection
/path/pathUtils
or would it look like
/path/shadowDetection/pathUtils
Your help and understanding is greatly appreciated.
This ReadMe you're referencing (from https://github.com/jflalonde/shadowDetection) is unclear, since it's not clear whether "shadowDetection" refers to the shadowDetection folder, or the shadowDetection software. If it's the former, then your first example (pathUtils alongside shadowDetection folder) would make sense; if it's the latter, then your second example (pathUtils inside shadowDetection folder) would apply.
My guess is that the author means parallels so I'd try it your first way first, but since it's ambiguously worded, try it the other way if it doesn't work. Once you figure it out, email the author and suggest he clarify his ReadMe.

Can I alter Python source code while executing?

What I mean by this is:
I have a program. The end user is currently using it. I submit a new piece of source code and expect it to run as if it were always there?
I can't find an answer that specifically answers the point.
I'd like to be able to say, "extend" or add new features (rather than fix something that's already there on the fly) to the program without requiring a termination of the program (eg. Restart or exit).
Yes, you can definitely do that in python.
Although, it opens a security hole, so be very careful.
You can easily do this by setting up a "loader" class that can collect the source code you want it to use and then call the exec builtin function, just pass some python source code in and it will be evaluated.
Check the package
http://opensourcehacker.com/2011/11/08/sauna-reload-the-most-awesomely-named-python-package-ever/ . It allows to overcome certain raw edges of plain exec. Also it may be worth to check Dynamically reload a class definition in Python

Creating a spec helper in rubymotion

I have some common methods used in a couple different specs, I want to extract them to some place like a spec helper that is accessible from all specs. Anyone know how to do this?
Here is something that sorta quacks like a spec_helper.
# _spec_helper.rb
module SpecHelper
::App::Persistence = {}
# global `before :each` ish
def self.extended(base)
base.before do
::App::Persistence.clear
end
end
def foo_helper
end
end
And then use it:
# my_view_spec.rb
describe "MyView" do
extend SpecHelper
before do
foo_helper
end
...
Two things to bear in mind:
Spec helper file is named in such way that it gets loaded first (leading underscore)
When running individual specs (e.g. files=my_view_spec.rb) helper file must go along - files=spec/my_view_spec.rb,spec/_spec_helper.rb
I just throw my common methods used in specs as they are (not encapsulated in a Module or anything) in a spec/support/utilities.rb file and Rubymotion seems to pick them up fine, though I don't know if this is the "proper" way to do this.
According to current http://www.rubymotion.com/developer-center/articles/testing/#_spec_helpers
Spec helpers are created under the spec/helpers directory of a RubyMotion project. An example could be spec/helpers/extension.rb.

Getting echofunc.vim to work

I came across echofunc.vim today (from a link in SO). Since I'm rubbish at remembering the order of function parameters, it looked like a very useful tool for me.
But the documentation is a bit lean on installation! And I've not been able to find any supplementary resources on the internet.
I'm trying to get it running on a RHEL box. I've copied the script into ~/.vim/plugin/echofunc.vim however no prompt when I type in a function name followed by '('. I've tried adding
let g:EchoFuncLangsUsed = ["php","java","cpp"]
to my .vimrc - still no prompting.
I'm guessing it needs to read from a dictionary somewhere - although there is a file in /usr/share/vim/vim70/ftplugin/php.vim, this is the RH default and does not include an explicit function list.
I'm not too bothered about getting hints on the functions/methods I've defined - just trying to get hints for the built-in functions. I can see there is a dictionary file available here which appears to provide the resources required for echofunc.vim, I can't see how I set this up.
TIA,
It expects a tags file, the last line of the description describes exactly how to generate it:
ctags -R --fields=+lS .
It works here with PHP but not with JS. Your mileage may vary.
I didn't know about this plugin, thanks for the info.
You should try phpcomplete.vim, it shows a prototype of the current function in a scratchpad. It is PHP only, though.

Resources