Install rpm file after gbs building 25/172325/1
authorSangYong Park <sy302.park@samsung.com>
Tue, 13 Mar 2018 07:53:34 +0000 (16:53 +0900)
committerSangYong Park <sy302.park@samsung.com>
Tue, 13 Mar 2018 07:57:16 +0000 (16:57 +0900)
If target device/emulator is connected,
then, install rpm file after gbs building.

Change-Id: I32f9d2de9acf71a4865b1a7022a199925aa97979
Signed-off-by: SangYong Park <sy302.park@samsung.com>
tizen/script/build
tizen/script/gbs.conf
tizen/script/install_rpm [new file with mode: 0755]

index 23aceb0..7e8b86e 100755 (executable)
@@ -51,7 +51,8 @@ def main():
         else:
           print 'Error: Fail to find valid profile (Please refer print_list option)'
         return 1
-      build_gbs(profile, args.force_bootstrap, args.verbose)
+      if build_gbs(profile, args.force_bootstrap, args.verbose):
+        subprocess.call([sys.executable, os.path.join(SCRIPT_PATH, 'install_rpm')])
   else:
     print 'Error: Cannot found any hint for build profile.'
     parser.print_help()
@@ -121,8 +122,7 @@ def build_gbs(profile, force_bootstrap, verbose):
   print 'Build : profile=' + profile + ' architecture=' + arch
   command = ['gbs', '--conf', os.path.join(SCRIPT_PATH, 'gbs.conf'), 'build',
              '-P', profile, '--include-all', '-A', arch, '--incremental']
-  subprocess.call(command)
-  return True
+  return True if subprocess.call(command) == 0 else False
 
 def find_architecture(profile):
   if profile.startswith('tztv'):
index f25aa88..2a16e4b 100755 (executable)
@@ -63,7 +63,7 @@ url = http://10.113.138.88/tizenrepo/electron_repo/armv7l/
 [profile.tz_v4.0_standard_armv7l]
 obs = obs.tizen_v4.0
 repos = repo.electron_armv7l, repo.public_4.0_base_arm, repo.tz_v4.0_standard
-buildroot = ~/GBS-ROOT-4.0-STANDARD-ARMV7L2
+buildroot = ~/GBS-ROOT-4.0-STANDARD-ARMV7L
 
 ###############################################
 #
diff --git a/tizen/script/install_rpm b/tizen/script/install_rpm
new file mode 100755 (executable)
index 0000000..919b227
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+
+import argparse
+import glob
+import os
+import subprocess
+import sys
+
+def main():
+  parser = argparse.ArgumentParser(description=('Install Programmable Web Runtime RPM'))
+  parser.add_argument('-r', '--root', help='Specify GBS root path', default='~/GBS-ROOT*')
+  parser.add_argument('-f', '--file', help='Specify RPM file to install')
+  args = parser.parse_args()
+
+  rpm_file = args.file if args.file else find_rpm(args.root)
+  if not rpm_file:
+    print 'Error: Fail to find RPM file in %s.' % args.root
+    return 1
+  elif not os.path.isfile(rpm_file):
+    print 'Error: RPM file (%s) is not exist.' % rpm_file
+    return 1
+
+  print 'Install RPM file (%s)' % rpm_file
+  if not install_rpm(rpm_file):
+    print 'Error: Fail to install RPM file.'
+    return 1
+  print 'Installation is done.'
+  return 0
+
+def find_rpm(root_path):
+  root_path = os.path.abspath(os.path.expanduser(root_path))
+  rpm_path = os.path.join(root_path, 'local', 'repos', '*', '*', 'RPMS')
+  command = ['find'] + glob.glob(rpm_path) + ['-name', '*.rpm']
+  for ex in ['*debug*', '*devel*']:
+    command += ['-and', '!', '-name', ex]
+  try:
+    files = subprocess.check_output(command).strip().split('\n')
+    files.sort(key=os.path.getmtime, reverse=True)
+    return files[0]
+  except subprocess.CalledProcessError:
+    return None
+
+def install_rpm(rpm_file):
+  name = os.path.basename(rpm_file)
+  units = name.split('.')
+  package = units[0]
+  if '-' in package:
+    package, _ = package.rsplit('-', 1)
+  arch = units[-2]
+  target_option = '-d' if arch == 'armv7l' or arch == 'aarch64' else '-e'
+  try:
+    subprocess.check_call(['sdb', target_option, 'root', 'on'])
+    subprocess.check_call(['sdb', target_option, 'push', rpm_file, '/opt/usr'])
+    subprocess.check_call(['sdb', target_option, 'shell', 'mount', '-o', 'remount,rw', os.sep])
+    subprocess.call(['sdb', target_option, 'shell', 'rpm', '-e', package])
+    subprocess.check_call(['sdb', target_option, 'shell', 'rpm', '-Uh', '--force', '--nodeps',
+                           os.path.join(os.sep, 'opt', 'usr', name)])
+    subprocess.call(['sdb', target_option, 'shell', 'tpk-backend', '--preload', '-y',
+                     'org.tizen.' + package]) # TODO : check needs
+    subprocess.call(['sdb', target_option, 'shell', 'reboot', '-f'])
+  except subprocess.CalledProcessError:
+    return False
+  return True
+
+if __name__ == '__main__':
+  sys.exit(main())