2
# vim: ai ts=4 sts=4 et sw=4
4
# Copyright (c) 2009 Intel Corporation
6
# This program is free software; you can redistribute it and/or modify it
7
# under the terms of the GNU General Public License as published by the Free
8
# Software Foundation; version 2 of the License
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
# You should have received a copy of the GNU General Public License along
16
# with this program; if not, write to the Free Software Foundation, Inc., 59
17
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
from spectacle import specify
23
from spectacle import logger
25
def parse_options(args):
26
import spectacle.__version__
28
usage = "Usage: %prog [options] [yaml-path]"
29
parser = optparse.OptionParser(usage, version=spectacle.__version__.VERSION)
31
parser.add_option("-o", "--output", type="string",
32
dest="outfile_path", default=None,
33
help="Path of output spec file")
34
parser.add_option("-s", "--skip-scm", action="store_true",
35
dest="skip_scm", default=False,
36
help="Skip to check upstream SCM when specified in YAML")
37
parser.add_option("-N", "--not-download", action="store_true",
38
dest="not_download", default=False,
39
help="Do not try to download newer source files")
41
return parser.parse_args()
43
if __name__ == '__main__':
46
(options, args) = parse_options(sys.argv[1:])
49
# no YAML-path specified, search in CWD
51
yamlls = glob.glob('*.yaml')
53
logger.error('Cannot find valid spectacle file(*.yaml) in current directory, please specify one.')
55
logger.error('Find multiple spectacle files(*.yaml) in current directory, please specify one.')
57
yaml_fpath = yamlls[0]
61
# check if the input file exists
62
if not os.path.exists(yaml_fpath):
63
# input file does not exist
64
logger.error("%s: File does not exist" % yaml_fpath)
66
if options.outfile_path:
67
out_fpath = os.path.abspath(options.outfile_path)
69
# %{name}.spec as the default if not specified
72
# check the working path
73
if yaml_fpath.find('/') != -1 and os.path.dirname(yaml_fpath) != os.path.curdir:
74
wdir = os.path.dirname(yaml_fpath)
75
logger.info('Changing to working dir: %s' % wdir)
78
yaml_fname = os.path.basename(yaml_fpath)
80
# check Makefile from packaging-tools
81
if not os.path.exists('Makefile'):
82
logger.warning('There is no "Makefile" for this package, please update it using packaging-tools')
84
spec_fpath, newspec = specify.generate_rpm(yaml_fname, spec_fpath=out_fpath, download_new=not options.not_download, skip_scm=options.skip_scm)
86
logger.warning("NEW spec file created: %s, maybe customized spec content is needed!" % spec_fpath)
88
logger.info("Old spec file exists, patching %s ..." % spec_fpath)