Skip to content

Commit

Permalink
update contrib & share scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
OnGle committed Sep 14, 2021
1 parent c0ef729 commit 3f6ed37
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
8 changes: 4 additions & 4 deletions contrib/cryptpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def random_salt():
return "".join([SALTCHARS[random.randint(0, len(SALTCHARS) - 1)] for i in range(2)])

def fatal(s):
print >> sys.stderr, "error: " + str(s)
print("error: " + str(s), file=sys.stderr)
sys.exit(1)

def usage():
print "Syntax: %s" % sys.argv[0]
print __doc__.strip()
print("Syntax: %s" % sys.argv[0])
print(__doc__.strip())

sys.exit(1)

Expand All @@ -51,7 +51,7 @@ def main():
else:
password = sys.stdin.readline().rstrip("\n")

print crypt.crypt(password, random_salt())
print(crypt.crypt(password, random_salt()))

if __name__ == "__main__":
main()
Expand Down
37 changes: 18 additions & 19 deletions contrib/iso2usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@
import sys
import stat
import getopt

import executil
import subprocess

def fatal(e):
print >> sys.stderr, 'Error: ' + str(e)
print('Error: ' + str(e), file=sys.stderr)
sys.exit(1)

def usage(e=None):
if e:
print >> sys.stderr, 'Error: ' + str(e)
print('Error: ' + str(e), file=sys.stderr)

cmd = os.path.basename(sys.argv[0])
print >> sys.stderr, 'Syntax: %s iso_path usb_device' % cmd
print >> sys.stderr, __doc__.strip()
print('Syntax: %s iso_path usb_device' % cmd, file=sys.stderr)
print(__doc__.strip(), file=sys.stderr)

sys.exit(1)

Expand All @@ -58,14 +57,14 @@ def __init__(self, path):
raise Error("iso path does not exist: %s" % self.path)

def make_hybrid(self):
executil.system("isohybrid", self.path)
subprocess.run(["isohybrid", self.path])

if not self.is_hybrid:
raise Error("iso not verified as hybrid mode")

@property
def is_hybrid(self):
output = executil.getoutput("fdisk", "-l", self.path)
output = subprocess.run(["fdisk", "-l", self.path], text=True).stdout
if "Hidden HPFS/NTFS" in output:
return True

Expand Down Expand Up @@ -116,17 +115,17 @@ def is_usb_device(self):
@property
def name(self):
cmd = ["udevadm", "info", "-q", "symlink", "-n", self.path]
output = executil.getoutput(*cmd)
output = subprocess.run(cmd, text=True).stdout
return output.split(" ")[0]

def write_iso(self, iso_path):
cmd = ["dd", "if=%s" % iso_path, "of=%s" % self.path]
executil.system(*cmd)
subprocess.run(cmd)

def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', ['help'])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
usage(e)

for opt, val in opts:
Expand All @@ -142,23 +141,23 @@ def main():
try:
iso = ISO(args[0])
usb = USB(args[1])
except Error, e:
except Error as e:
fatal(e)

print "*" * 78
print "iso: %s (hybrid: %s)" % (iso.name, iso.is_hybrid)
print "usb: %s (%s)" % (usb.name, usb.path)
print "*" * 78
print("*" * 78)
print("iso: %s (hybrid: %s)" % (iso.name, iso.is_hybrid))
print("usb: %s (%s)" % (usb.name, usb.path))
print("*" * 78)

cont = raw_input("Is the above correct? (y/N): ").strip()
cont = input("Is the above correct? (y/N): ").strip()
if not cont.lower() == "y":
fatal("aborting...")

if not iso.is_hybrid:
print "processing ISO for hybrid mode..."
print("processing ISO for hybrid mode...")
iso.make_hybrid()

print "writing ISO to USB, this could take a while..."
print("writing ISO to USB, this could take a while...")
usb.write_iso(iso.path)


Expand Down
14 changes: 7 additions & 7 deletions share/make-release-deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from string import Template

from temp import TempDir
from executil import system
import subprocess

CONTROL_TPL = """\
Package: $NAME
Expand All @@ -53,10 +53,10 @@ class Error(Exception):

def usage(e=None):
if e:
print >> sys.stderr, "Error: " + str(e)
print("Error: " + str(e), file=sys.stderr)

print >> sys.stderr, "Syntax: %s path/to/changelog path/to/output" % sys.argv[0]
print >> sys.stderr, __doc__.strip()
print("Syntax: %s path/to/changelog path/to/output" % sys.argv[0], file=sys.stderr)
print(__doc__.strip(), file=sys.stderr)

sys.exit(1)

Expand Down Expand Up @@ -91,19 +91,19 @@ def make_release_deb(path_changelog, path_output, depends=[]):
VERSION=version,
MAINTAINER=maintainer,
DEPENDS=", ".join(depends))
print >> control, re.sub("Depends: \n", "", content),
print(re.sub("Depends: \n", "", content), end=' ', file=control)
control.close()

tmpdir_doc = join(tmpdir.path, "usr/share/doc/" + name)
os.makedirs(tmpdir_doc)

shutil.copy(path_changelog, tmpdir_doc)
system("dpkg-deb -b", tmpdir.path, path_output)
subprocess.run(["dpkg-deb", "-b", tmpdir.path, path_output])

def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'h', ['dep='])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
usage(e)

if len(args) != 2:
Expand Down
12 changes: 6 additions & 6 deletions share/turnkey-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

def usage(e=None):
if e:
print >> sys.stderr, "error: " + str(e)
print("error: " + str(e), file=sys.stderr)

print >> sys.stderr, "Syntax: %s path/to/changelog architecture" % sys.argv[0]
print("Syntax: %s path/to/changelog architecture" % sys.argv[0], file=sys.stderr)
sys.exit(1)

class Error(Exception):
pass

def fatal(s):
print >> sys.stderr, "error: " + str(s)
print("error: " + str(s), file=sys.stderr)
sys.exit(1)

def parse_changelog(fpath):
Expand All @@ -65,7 +65,7 @@ def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], 'h',
['dist=', 'tag='])
except getopt.GetoptError, e:
except getopt.GetoptError as e:
usage(e)

if len(args) != 2:
Expand All @@ -86,8 +86,8 @@ def main():
version_tag = val

try:
print get_turnkey_version(changelog_path, architecture, dist_override, version_tag)
except Error, e:
print(get_turnkey_version(changelog_path, architecture, dist_override, version_tag))
except Error as e:
fatal(e)

if __name__=="__main__":
Expand Down
4 changes: 2 additions & 2 deletions tests/parseopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

for opt, val in opts:
if opt == '-I':
print "INCLUDE: " + val
print("INCLUDE: " + val)
elif opt == '-D':
print "DEFINE: " + val
print("DEFINE: " + val)

0 comments on commit 3f6ed37

Please sign in to comment.