~saviq/simplestreams/add-vhd-images

« back to all changes in this revision

Viewing changes to tools/sstream-mirror-glance

  • Committer: Scott Moser
  • Date: 2016-08-04 14:34:49 UTC
  • Revision ID: smoser@ubuntu.com-20160804143449-2vcpvvrni3tmqkp4
tools/run-flake8: run on all python programs in tools and fix errors

now tools/run-flake8 will run on all python programs in tools
by checking the first line for 'python'.  Then, fix all the reported
errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
DEFAULT_FILTERS = ['ftype~(disk1.img|disk.img)', 'arch~(x86_64|amd64|i386)']
35
35
 
 
36
 
36
37
def error(msg):
37
38
    sys.stderr.write(msg)
38
39
 
 
40
 
39
41
class StdoutProgressAggregator(util.ProgressAggregator):
40
42
    def __init__(self, remaining_items):
41
43
        super(StdoutProgressAggregator, self).__init__(remaining_items)
43
45
    def emit(self, progress):
44
46
        size = float(progress['size'])
45
47
        written = float(progress['written'])
46
 
        print("%.2f %s (%d of %d images)"
47
 
              " - %.2f" % (written / size,
48
 
                           progress['name'], 
49
 
                           self.total_image_count - len(self.remaining_items) + 1,
50
 
                           self.total_image_count,
51
 
                           float(self.total_written) / self.total_size))
 
48
        print("%.2f %s (%d of %d images) - %.2f" %
 
49
              (written / size, progress['name'],
 
50
               self.total_image_count - len(self.remaining_items) + 1,
 
51
               self.total_image_count,
 
52
               float(self.total_written) / self.total_size))
52
53
 
53
54
 
54
55
def main():
104
105
                        "Expressions are key[!]=literal_string "
105
106
                        "or key[!]~regexp.")
106
107
 
107
 
    parser.add_argument('--hypervisor-mapping', action='store_true', default=False,
 
108
    parser.add_argument('--hypervisor-mapping', action='store_true',
 
109
                        default=False,
108
110
                        help="Set hypervisor_type attribute on stored images "
109
 
                        "and the virt attribute in the associated stream data. "
110
 
                        "This is useful in OpenStack Clouds which use multiple "
111
 
                        "hypervisor types with in a single region.")
 
111
                        "and the virt attribute in the associated stream "
 
112
                        "data. This is useful in OpenStack Clouds which use "
 
113
                        "multiple hypervisor types with in a single region.")
112
114
 
113
115
    args = parser.parse_args()
114
116
 
124
126
 
125
127
    (mirror_url, args.path) = util.path_from_mirror_url(args.source_mirror,
126
128
                                                        args.path)
 
129
 
127
130
    def policy(content, path):  # pylint: disable=W0613
128
131
        if args.path.endswith('sjson'):
129
132
            return util.read_signed(content, keyring=args.keyring)
156
159
        mirror_config['content_id'] = args.content_id % {'region': region}
157
160
 
158
161
        if args.progress:
159
 
            drmirror = glance.ItemInfoDryRunMirror(config=mirror_config, objectstore=tstore)
 
162
            drmirror = glance.ItemInfoDryRunMirror(config=mirror_config,
 
163
                                                   objectstore=tstore)
160
164
            drmirror.sync(smirror, args.path)
161
165
            p = StdoutProgressAggregator(drmirror.items)
162
166
            progress_callback = p.progress_callback