blob: adb09bdb15a872e81d5209b30cd53ac36329209c [file] [log] [blame]
#!/usr/bin/env python3
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
"""
backport.wc - library for performing actions on the current WC
"""
import backport.merger
import logging
logger = logging.getLogger(__name__)
def get_wc_info():
"""Run svn info. Return a dictionary with the following elements:
URL: The WC url
BASE_revision: The WC base revision
Repository_root: The WC repository root
"""
(exit_code, stdout, stderr) = backport.merger.run_svn(["info"])
URL = ""
BASE_revision = ""
Repository_root = ""
for line in stdout.split('\n'):
if line.startswith('URL:'):
URL = line.split('URL:')[1].strip()
elif line.startswith('Revision:'):
BASE_revision = line.split('Revision:')[1].strip()
elif line.startswith('Repository Root:'):
Repository_root = line.split('Repository Root:')[1].strip()
return {"URL": URL,
"BASE_revision": BASE_revision,
"Repository_root": Repository_root,
}
def setUpModule():
"Set-up function, invoked by 'python -m unittest'."
# Suppress warnings generated by the test data.
# TODO: some test functions assume .assertLogs is available, they fail with
# AttributeError if it's absent (e.g., on python < 3.4).
try:
unittest.TestCase.assertLogs
except AttributeError:
logger.setLevel(logging.ERROR)
if __name__ == '__main__':
unittest.main()