Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata Files and Associated Verbs #80

Merged
merged 29 commits into from
Sep 23, 2014
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6626271
metadata: adding metadata util functions
jbohren Jul 3, 2014
30d9c78
init: creating new verb for declaring a catkin workspace by creating …
jbohren Jul 7, 2014
6e7238e
build: Enable storing and retrieving build information from catkin to…
jbohren Jul 7, 2014
5f86b63
metadata: Switching to use .catkin_tools directory
jbohren Jul 9, 2014
7d52720
clean: new verb
jbohren Jul 9, 2014
219bb46
build: Fixing issue on first creation of metadata dir
jbohren Jul 9, 2014
621aab6
PEP8 Fixes
jbohren Jul 10, 2014
b3de25b
build: Fix CMAKE_PREFIX_PATH and install when using metadata
jbohren Jul 16, 2014
53923e1
metadata: Adding preliminary support for independent metadata profiles
jbohren Jul 17, 2014
f95d408
MAJOR REFACTOR: Adding persistent context
jbohren Jul 18, 2014
53f990a
fill out template in copyright line in LICENSE
wjwwood Sep 17, 2014
6ed95b8
remove unused imports
wjwwood Sep 17, 2014
14e68b9
add missing imports
wjwwood Sep 17, 2014
9c8bbd9
remove unused variables
wjwwood Sep 17, 2014
d998661
purely style fixes, line length, unused variables
wjwwood Sep 17, 2014
be4b11b
docs: remove all trailing whitespace
wjwwood Sep 17, 2014
93ae7da
docs: fix length of headings (sphinx warning)
wjwwood Sep 17, 2014
d53b27e
docs: add missing newline which hid a code block
wjwwood Sep 17, 2014
12a2253
docs: add toc entry for profiles, remove others
wjwwood Sep 17, 2014
345d5d9
Merge pull request #1 from catkin/metadata-file-fixup
jbohren Sep 18, 2014
4f146ab
Delete profiles.rst
jbohren Sep 18, 2014
6ae0d96
Update index.rst
jbohren Sep 18, 2014
dc682eb
Fixing error introduced in 345d5d9
jbohren Sep 18, 2014
f7acbe0
doc: Adding correct DESTDIR info
jbohren Sep 18, 2014
81e48b5
Fixing cm vs cmi vs ct features
jbohren Sep 18, 2014
d3db6f4
init: fixing bad program option
jbohren Sep 19, 2014
fc8a3cd
testing: Adding some convenience functions to testing utils module, a…
jbohren Sep 20, 2014
a69725f
testing: making tests portable between python2 and python3
jbohren Sep 23, 2014
8475598
testing: python3 compatibility
jbohren Sep 23, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
metadata: adding metadata util functions
jbohren committed Jul 9, 2014
commit 66262714beb383a0d35e5206419d830c13bdb3b2
115 changes: 115 additions & 0 deletions catkin_tools/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Copyright 2014 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This set of functions define the interactions with the catkin_tools metadata
# file, `.catkin_tools.yml`. This file can be used by each verb to store
# verb-specific information

from __future__ import print_function

import os
import yaml

CATKIN_TOOLS_METADATA_FILE = '.catkin_tools.yml'

metadata_file_header = """\
### DO NOT EDIT, generated automatically and updated automatically by catkin_tools
### If you delete this file, it will cause `catkin build` to re-build from scratch.
### If you modify this file, it may have unintended side-effects on your workspace.
"""

def find_metadata_file(search_path):
"""Find the catkin_tools metadata file starting in the path given by
search_path and traversing each parent directory until either finding such
a file or getting to the root of the filesystem.

search_path: Directory which either is a catkin workspace or is contained
in a catkin workspace

returns: Path to the file if found, `None` if not found.
"""
while True:
# Check if marker file exists
candidate_path = os.path.join(search_path,CATKIN_TOOLS_METADATA_FILE)
if os.path.exists(candidate_path):
return candidate_path

# Update search path or end
(search_path, child_dir) = os.path.split(search_path)
if len(child_dir) == 0:
break

return None

def write_header(stream):
"""Write the metadata file header to a given stream.
"""
stream.write(metadata_file_header)

def init_metadata_file(workspace_path, force=False):
"""Create a catkin_tools metadata file with no content in a given path.

workspace_path: The path to the root of a catkin workspace
force: If true, overwrite an existing metadata file
"""

# Make sure the directory
if not os.path.exists(workspace_path):
raise IOError("Error: Can't initialize Catkin workspace in path %s because it does not exist." % (workspace_path))

# Construct the full path to the metadata file
metadata_file_path = os.path.join(workspace_path, CATKIN_TOOLS_METADATA_FILE)

# Check if a metadata file already exists
if os.path.exists(metadata_file_path):
if force:
print("Warning: Overwriting existing catkin metadata file: %s" % (metadata_file_path))
else:
raise IOError("Catkin metadata file already exists, not overwriting: %s" % (metadata_file_path))

# Write a metadata file which only contains a header
with open(metadata_file_path,'w') as metadata_file:
write_header(metadata_file)

return metadata_file_path

def get_metadata(metadata_file_path):
"""Get a python structure representing the information stored in the
catkin_tools metadata file.

metadata_file_path: The path to a catkin_tools metadata file
"""

with open(metadata_file_path,'r') as metadata_file:
return yaml.load(metadata_file)

def update_metadata(metadata_file_path,key,new_data):
"""Update the catkin_tools metadata file located either in search_path or
in one of the parent directories of search_path.

metadata_file_path: The path to a catkin_tools metadata file
key: The top-level key in the metadata file (usually the name of the
associated verb)
new_data: A python dictionary or array to write to the metadata file.
"""

# Get the curent metadata
data = get_metadata(metadata_file_path) or dict()

# Update the given key
data[key] = new_data
with open(metadata_file_path,'w') as metadata_file:
write_header(metadata_file)
yaml.dump(data, metadata_file, default_flow_style=False)