Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
ensembl-gh-mirror
ensembl-hive
Commits
d6bb2bf4
Commit
d6bb2bf4
authored
May 30, 2012
by
Leo Gordon
Browse files
a new JSON-based configuration file and parser
parent
c4e7aecf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
114 additions
and
0 deletions
+114
-0
hive_config.json
hive_config.json
+31
-0
modules/Bio/EnsEMBL/Hive/Utils/Config.pm
modules/Bio/EnsEMBL/Hive/Utils/Config.pm
+83
-0
No files found.
hive_config.json
0 → 100644
View file @
d6bb2bf4
{
"Graph"
:
{
"Colours"
:
{
"Status"
:
{
"BLOCKED"
:
"grey"
,
"LOADING"
:
"yellow"
,
"SYNCHING"
:
"yellow"
,
"READY"
:
"yellow"
,
"WORKING"
:
"yellow"
,
"ALL_CLAIMED"
:
"yellow"
,
"DONE"
:
"green"
,
"FAILED"
:
"red"
,
"OTHER"
:
"white"
,
"TABLE"
:
"black"
,
},
"Flows"
:
{
"data"
:
"blue"
,
"control"
:
"red"
,
"semablock"
:
"red"
,
},
},
"Fonts"
:
{
"node"
:
"Helvetica"
,
"edge"
:
"Helvetica"
,
},
"DisplayDetails"
:
1
,
"DisplaySemaphoreBoxes"
:
1
,
"DisplayStretched"
:
0
,
}
}
modules/Bio/EnsEMBL/Hive/Utils/Config.pm
0 → 100755
View file @
d6bb2bf4
#!/usr/bin/env perl
package
Bio::EnsEMBL::Hive::Utils::
Config
;
use
JSON
;
sub
new
{
my
$class
=
shift
@_
;
my
$self
=
bless
{},
$class
;
$self
->
config_hash
(
{}
);
foreach
my
$cfg_file
(
@
_
)
{
if
(
my
$cfg_hash
=
$self
->
load_from_json
(
$cfg_file
))
{
$self
->
merge
(
$cfg_hash
);
}
}
return
$self
;
}
sub
config_hash
{
my
$self
=
shift
@_
;
if
(
@
_
)
{
$self
->
{
_config_hash
}
=
shift
@_
;
}
return
$self
->
{
_config_hash
};
}
sub
load_from_json
{
my
(
$self
,
$filename
)
=
@_
;
if
(
-
r
$filename
)
{
my
$json_text
=
`
cat
$filename
`;
my
$json_parser
=
JSON
->
new
->
relaxed
;
my
$perl_hash
=
$json_parser
->
decode
(
$json_text
);
return
$perl_hash
;
}
else
{
warn
"
Can't read from '
$filename
'
";
return
undef
;
}
}
sub
merge
{
my
$self
=
shift
@_
;
my
$from
=
shift
@_
;
my
$to
=
shift
@
_
||
$self
->
config_hash
;
# only defined in subsequent recursion steps
while
(
my
(
$key
,
$value
)
=
each
%$from
)
{
if
(
exists
$to
->
{
$key
}
and
ref
(
$to
->
{
$key
}))
{
$self
->
merge
(
$from
->
{
$key
},
$to
->
{
$key
});
}
else
{
$to
->
{
$key
}
=
$from
->
{
$key
};
}
}
}
sub
get
{
my
$self
=
shift
@_
;
my
$option_name
=
pop
@_
;
my
$hash_ptr
=
$self
->
config_hash
;
my
$option_value
=
$hash_ptr
->
{
$option_name
};
# not necessatily defined
foreach
my
$context_syll
(
@
_
)
{
$hash_ptr
=
$hash_ptr
->
{
$context_syll
};
if
(
exists
$hash_ptr
->
{
$option_name
})
{
$option_value
=
$hash_ptr
->
{
$option_name
};
}
}
return
$option_value
;
}
1
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment