~ubuntu-branches/ubuntu/quantal/spectacle/quantal

« back to all changes in this revision

Viewing changes to tools/specify

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2010-08-08 20:01:42 UTC
  • Revision ID: james.westby@ubuntu.com-20100808200142-q09anvq02isk4o6n
Tags: upstream-0.18+git19+4768025
ImportĀ upstreamĀ versionĀ 0.18+git19+4768025

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python -tt
 
2
# vim: ai ts=4 sts=4 et sw=4
 
3
 
 
4
#    Copyright (c) 2009 Intel Corporation
 
5
#
 
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
 
9
#
 
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
 
13
#    for more details.
 
14
#
 
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.
 
18
 
 
19
import os,sys
 
20
import optparse
 
21
 
 
22
from spectacle import specify
 
23
from spectacle import logger
 
24
 
 
25
def parse_options(args):
 
26
    import spectacle.__version__
 
27
 
 
28
    usage = "Usage: %prog [options] [yaml-path]"
 
29
    parser = optparse.OptionParser(usage, version=spectacle.__version__.VERSION)
 
30
 
 
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")
 
40
 
 
41
    return parser.parse_args()
 
42
 
 
43
if __name__ == '__main__':
 
44
    """ Main Function """
 
45
 
 
46
    (options, args) = parse_options(sys.argv[1:])
 
47
 
 
48
    if not args:
 
49
        # no YAML-path specified, search in CWD
 
50
        import glob
 
51
        yamlls = glob.glob('*.yaml')
 
52
        if not yamlls:
 
53
            logger.error('Cannot find valid spectacle file(*.yaml) in current directory, please specify one.')
 
54
        elif len(yamlls) > 1:
 
55
            logger.error('Find multiple spectacle files(*.yaml) in current directory, please specify one.')
 
56
 
 
57
        yaml_fpath = yamlls[0]
 
58
    else:
 
59
        yaml_fpath = args[0]
 
60
 
 
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)
 
65
 
 
66
    if options.outfile_path:
 
67
        out_fpath = os.path.abspath(options.outfile_path)
 
68
    else:
 
69
        # %{name}.spec as the default if not specified
 
70
        out_fpath = None
 
71
 
 
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)
 
76
        os.chdir(wdir)
 
77
 
 
78
    yaml_fname = os.path.basename(yaml_fpath)
 
79
 
 
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')
 
83
 
 
84
    spec_fpath, newspec = specify.generate_rpm(yaml_fname, spec_fpath=out_fpath, download_new=not options.not_download, skip_scm=options.skip_scm)
 
85
    if newspec:
 
86
        logger.warning("NEW spec file created: %s, maybe customized spec content is needed!" % spec_fpath)
 
87
    else:
 
88
        logger.info("Old spec file exists, patching %s ..." % spec_fpath)