#!/usr/bin/env python
-# Copyright (C) 2011 GRNET S.A.
+# Copyright (C) 2011 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
from StringIO import StringIO
from optparse import OptionParser
+
def parse_arguments(input_args):
usage = "Usage: %prog [options] <output_file>"
parser = OptionParser(usage=usage)
parser.add_option("-i", "--input",
- action="store",type='string', dest="input_file",
- help="get input from FILE instead of stdin",
- metavar="FILE")
+ action="store", type='string', dest="input_file",
+ help="get input from FILE instead of stdin",
+ metavar="FILE")
opts, args = parser.parse_args(input_args)
if len(args) != 1:
parser.error('output file is missing')
output_file = args[0]
-
+
if opts.input_file is not None:
if not os.path.isfile(opts.input_file):
parser.error('input file does not exist')
-
+
return (opts.input_file, output_file)
os.environ['SNF_IMAGE_PROPERTY_' + str(key).upper()] = value
p = subprocess.Popen(['bash', '-c', 'set'], stdout=subprocess.PIPE)
- output = StringIO(p.communicate()[0]);
+ output = StringIO(p.communicate()[0])
for line in iter(output):
if line.startswith('SNF_IMAGE_PROPERTY_'):
outfh.write('export ' + line)
) = struct.unpack(self.format, raw_part)
def pack(self):
- return struct.pack(self.format,
+ return struct.pack
+ (
+ self.format,
self.status,
self.start,
self.type,
def __init__(self, block):
raw_part = {}
self.code_area, \
- raw_part[0], \
- raw_part[1], \
- raw_part[2], \
- raw_part[3], \
- self.signature = struct.unpack(self.format, block)
+ raw_part[0], \
+ raw_part[1], \
+ raw_part[2], \
+ raw_part[3], \
+ self.signature = struct.unpack(self.format, block)
self.part = {}
for i in range(4):
def pack(self):
"""Packs an MBR to a binary string."""
- return struct.pack(self.format,
+ return struct.pack(
+ self.format,
self.code_area,
self.part[0].pack(),
self.part[1].pack(),
def __init__(self, block):
self.signature, \
- self.revision, \
- self.hdr_size, \
- self.header_crc32, \
- self.current_lba, \
- self.backup_lba, \
- self.first_usable_lba, \
- self.last_usable_lba, \
- self.uuid, \
- self.part_entry_start, \
- self.part_count, \
- self.part_entry_size, \
- self.part_crc32 = struct.unpack(self.format, block)
-
- def pack(self):
- """Packs a GPT Header to a binary string."""
- return struct.pack(self.format,
- self.signature, \
self.revision, \
self.hdr_size, \
self.header_crc32, \
self.part_entry_start, \
self.part_count, \
self.part_entry_size, \
+ self.part_crc32 = struct.unpack(self.format, block)
+
+ def pack(self):
+ """Packs a GPT Header to a binary string."""
+ return struct.pack(
+ self.format,
+ self.signature,
+ self.revision,
+ self.hdr_size,
+ self.header_crc32,
+ self.current_lba,
+ self.backup_lba,
+ self.first_usable_lba,
+ self.last_usable_lba,
+ self.uuid,
+ self.part_entry_start,
+ self.part_count,
+ self.part_entry_size,
self.part_crc32
)
# Partition entries (LBA 2...34)
d.seek(self.primary.part_entry_start * BLOCKSIZE)
entries_size = self.primary.part_count * \
- self.primary.part_entry_size
+ self.primary.part_entry_size
self.part_entries = d.read(entries_size)
# Secondary GPT Header (LBA -1)
self.primary.backup_lba = lba_count - 1 # LBA-1
self.primary.last_usable_lba = lba_count - 34 # LBA-34
self.primary.header_crc32 = \
- binascii.crc32(self.primary.pack()) & 0xffffffff
+ binascii.crc32(self.primary.pack()) & 0xffffffff
# Fix Secondary header
self.secondary.header_crc32 = 0
self.secondary.last_usable_lba = lba_count - 34 # LBA-34
self.secondary.part_entry_start = lba_count - 33 # LBA-33
self.secondary.header_crc32 = \
- binascii.crc32(self.secondary.pack()) & 0xffffffff
+ binascii.crc32(self.secondary.pack()) & 0xffffffff
# Copy the new partition table back to the device
with open(self.disk, "wb") as d:
usage = "Usage: %prog [options] <target>"
parser = OptionParser(usage=usage)
parser.add_option("-i", "--input",
- action="store", type='string', dest="input_file",
- help="get input from FILE instead of stdin",
- metavar="FILE")
- parser.add_option("-d", "--decode",
- action="store_true", dest="decode", default=False,
- help="decode files under target and create manifest")
+ action="store", type='string', dest="input_file",
+ help="get input from FILE instead of stdin",
+ metavar="FILE")
+ parser.add_option("-d", "--decode", action="store_true", dest="decode",
+ default=False,
+ help="decode files under target and create manifest")
opts, args = parser.parse_args(input_args)
#!/usr/bin/env python
-# Copyright (C) 2011 GRNET S.A.
+# Copyright (C) 2011 GRNET S.A.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""
import sys
-import crypt
+import crypt
from string import ascii_letters, digits
from random import choice
'sha512': '6'
}
+
def random_salt(length=8):
pool = ascii_letters + digits + "/" + "."
return ''.join(choice(pool) for i in range(length))
def parse_arguments(input_args):
usage = "usage: %prog [-h] [-m encrypt-method] <password>"
parser = OptionParser(usage=usage)
- parser.add_option("-m", "--encrypt-method",
- dest="encrypt_method",
- type='choice',
- default="sha512",
- choices=HASH_ID_FROM_METHOD.keys(),
- help="encrypt password with ENCRYPT_METHOD [%default] \
- (supported: " + ", ".join(HASH_ID_FROM_METHOD.keys()) +")",
+ parser.add_option(
+ "-m", "--encrypt-method", dest="encrypt_method", type='choice',
+ default="sha512", choices=HASH_ID_FROM_METHOD.keys(),
+ help="encrypt password with ENCRYPT_METHOD [%default] (supported: " +
+ ", ".join(HASH_ID_FROM_METHOD.keys()) + ")"
)
(opts, args) = parser.parse_args(input_args)
if len(args) != 1:
- parser.error('password is missing')
+ parser.error('password is missing')
return (args[0], opts.encrypt_method)
def main():
- (password, method) = parse_arguments(sys.argv[1:])
+ (passwd, method) = parse_arguments(sys.argv[1:])
salt = random_salt()
- hash = crypt.crypt(password, "$"+HASH_ID_FROM_METHOD[method]+"$"+salt)
+ hash = crypt.crypt(passwd, "$" + HASH_ID_FROM_METHOD[method] + "$" + salt)
sys.stdout.write("%s\n" % (hash))
return 0
import signal
import socket
-MSG_TYPE="image-copy-progress"
+MSG_TYPE = "image-copy-progress"
+
def parse_arguments(args):
from optparse import OptionParser
parser.add_option("-r", "--read-bytes",
action="store", type="int", dest="read_bytes",
metavar="BYTES_TO_READ",
- help="The expected number of bytes to be read, " \
+ help="The expected number of bytes to be read, "
"used to compute input progress",
default=None)
- parser.add_option("-o", "--output_fd", dest="output", default=None,
- metavar="FILE", type="int",
- help="Write output notifications to this file descriptor")
+ parser.add_option(
+ "-o", "--output_fd", dest="output", default=None, metavar="FILE",
+ type="int", help="Write output notifications to this file descriptor")
(opts, args) = parser.parse_args(args)
sys.stderr.write("Child PID = %d stopped by signal, signal = %d\n" %
(pid, os.WSTOPSIG(status)))
else:
- sys.stderr.write("Internal error: Unhandled case, " \
+ sys.stderr.write("Internal error: Unhandled case, "
"PID = %d, status = %d\n" % (pid, status))
sys.exit(1)
sys.stderr.flush()
if wpid == pid:
report_wait_status(pid, status)
if (os.WIFEXITED(status) or os.WIFSIGNALED(status)):
- if not (os.WIFEXITED(status) and
- os.WEXITSTATUS(status) == 0):
+ if not (os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0):
return 1
else:
message['position'] = message['total']
default=None, metavar="IFNAME",
help="listen on interface IFNAME for monitoring data")
- parser.add_option("-f", "--filter", type="string", dest="filter",
+ parser.add_option(
+ "-f", "--filter", type="string", dest="filter",
help="add FILTER to incomint traffice when working on an interface",
default=None, metavar="FILTER")
options.fd = args[0]
if options.filter is not None and options.ifname is None:
- parser.error('You need to define an interface since filters are' \
+ parser.error('You need to define an interface since filters are'
'defined')
return options
if self.lines_left > STDERR_MAXLINES:
error("Too many lines in the STDERR output")
elif self.lines_left < 0:
- error("Second field of STDERR: %d is invalid" % self.lines_left)
+ error("Second field of STDERR: %d is invalid" %
+ self.lines_left)
if self.lines_left > 0:
self.stderr = m.group(2) + "\n"
self.send("STDERR", self.stderr)
self.stderr = ""
elif self.line.startswith("TASK_START:") \
- or self.line.startswith("TASK_END:") \
- or self.line.startswith("WARNING:") \
- or self.line.startswith("ERROR:"):
+ or self.line.startswith("TASK_END:") \
+ or self.line.startswith("WARNING:") \
+ or self.line.startswith("ERROR:"):
(msg_type, _, value) = self.line.partition(':')
if self.line.startswith("WARNING:") or \
- self.line.startswith("ERROR:"):
+ self.line.startswith("ERROR:"):
value = [value]
self.send(msg_type, value)
else:
if options.ifname is not None:
try:
sniff(filter=options.filter, iface=options.ifname,
- prn=lambda x: monitor.process(x.payload.getfieldval("load")))
+ prn=lambda x: monitor.process(x.payload.getfieldval("load")))
except socket.error as e:
# Network is down
if e.errno == 100:
msg_type = sys.argv[1]
- if msg_type not in PROTOCOL.keys():
+ if msg_type not in PROTOCOL.keys():
sys.stderr.write("Unknown message type: %s\n" % msg_type)
sys.exit(1)