From b6442acf80a8872e70d67a6a2bde3db09fa43a8c Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Wed, 30 Sep 2015 12:39:49 +0100 Subject: [PATCH] device: more reliable get_properites Pulling entries from procfs does not work on some platforms. This commit updates get_properites() to cat the contents of a property_file and write it to output file on the host, rather than pulling it (directories are still pulled). --- wlauto/common/linux/device.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py index daa3f40c..b1364559 100644 --- a/wlauto/common/linux/device.py +++ b/wlauto/common/linux/device.py @@ -191,12 +191,16 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method def get_properties(self, context): for propfile in self.property_files: - if not self.file_exists(propfile): - continue try: normname = propfile.lstrip(self.path.sep).replace(self.path.sep, '.') outfile = os.path.join(context.host_working_directory, normname) - self.pull_file(propfile, outfile) + if self.is_file(propfile): + with open(outfile, 'w') as wfh: + wfh.write(self.execute('cat {}'.format(propfile))) + elif self.is_directory(propfile): + self.pull_file(propfile, outfile) + else: + continue except DeviceError: # We pull these files "opportunistically", so if a pull fails # (e.g. we don't have permissions to read the file), just note @@ -722,6 +726,18 @@ class LinuxDevice(BaseLinuxDevice): # split out everything except the last word. return boolean(output.split()[-1]) # pylint: disable=maybe-no-member + def is_file(self, filepath): + output = self.execute('if [ -f \'{}\' ]; then echo 1; else echo 0; fi'.format(filepath)) + # output from ssh my contain part of the expression in the buffer, + # split out everything except the last word. + return boolean(output.split()[-1]) # pylint: disable=maybe-no-member + + def is_directory(self, filepath): + output = self.execute('if [ -d \'{}\' ]; then echo 1; else echo 0; fi'.format(filepath)) + # output from ssh my contain part of the expression in the buffer, + # split out everything except the last word. + return boolean(output.split()[-1]) # pylint: disable=maybe-no-member + def listdir(self, path, as_root=False, **kwargs): contents = self.execute('ls -1 {}'.format(path), as_root=as_root).strip() if not contents: