6be8ef3906
make most of modules use openstack.common.cfg instead of gflags caveats: no config file compatibility is provided. (flagfile vs ini file) Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
86 lines
2.8 KiB
Python
86 lines
2.8 KiB
Python
# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation.
|
|
# Copyright (C) 2011 Isaku Yamahata <yamahata at valinux co jp>
|
|
#
|
|
# 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.
|
|
|
|
|
|
import inspect
|
|
import logging
|
|
import os
|
|
import sys
|
|
import re
|
|
|
|
LOG = logging.getLogger('ryu.utils')
|
|
|
|
|
|
def import_module(modname):
|
|
try:
|
|
__import__(modname)
|
|
except:
|
|
sys.path.append(os.path.dirname(os.path.abspath(modname)))
|
|
name = os.path.basename(modname)
|
|
if name.endswith('.py'):
|
|
name = name[:-3]
|
|
__import__(name)
|
|
return sys.modules[name]
|
|
return sys.modules[modname]
|
|
|
|
|
|
def round_up(x, y):
|
|
return ((x + y - 1) / y) * y
|
|
|
|
|
|
def hex_array(data):
|
|
return ' '.join(hex(ord(chr)) for chr in data)
|
|
|
|
|
|
# the following functions are taken from OpenStack
|
|
#
|
|
# Get requirements from the first file that exists
|
|
def get_reqs_from_files(requirements_files):
|
|
for requirements_file in requirements_files:
|
|
if os.path.exists(requirements_file):
|
|
with open(requirements_file, 'r') as fil:
|
|
return fil.read().split('\n')
|
|
return []
|
|
|
|
|
|
def parse_requirements(requirements_files=['requirements.txt',
|
|
'tools/pip-requires']):
|
|
requirements = []
|
|
for line in get_reqs_from_files(requirements_files):
|
|
# For the requirements list, we need to inject only the portion
|
|
# after egg= so that distutils knows the package it's looking for
|
|
# such as:
|
|
# -e git://github.com/openstack/nova/master#egg=nova
|
|
if re.match(r'\s*-e\s+', line):
|
|
requirements.append(re.sub(r'\s*-e\s+.*#egg=(.*)$', r'\1',
|
|
line))
|
|
# such as:
|
|
# http://github.com/openstack/nova/zipball/master#egg=nova
|
|
elif re.match(r'\s*https?:', line):
|
|
requirements.append(re.sub(r'\s*https?:.*#egg=(.*)$', r'\1',
|
|
line))
|
|
# -f lines are for index locations, and don't get used here
|
|
elif re.match(r'\s*-f\s+', line):
|
|
pass
|
|
# argparse is part of the standard library starting with 2.7
|
|
# adding it to the requirements list screws distro installs
|
|
elif line == 'argparse' and sys.version_info >= (2, 7):
|
|
pass
|
|
else:
|
|
requirements.append(line)
|
|
|
|
return requirements
|