Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_extract_versions(self, i, expected):
if i != 4 or utils.PY3:
with self.e[i].archive:
pkgdata = self.e[i].extract_data()
assert pkgdata.data['python_versions'] == expected
@utils.memoize_by_args
def memoized(self, num):
if hasattr(self, "memoized_called"):
raise BaseException('This should not have been called!')
else:
setattr(self, "memoized_called", True)
return num
def test_rpm_eval(self):
if os.path.exists('/usr/bin/rpm'):
assert utils.rpm_eval('macro') == 'macro'
else:
assert utils.rpm_eval('macro') == ''
def run(self, interpreter):
"""Executes the code of the specified module. Deserializes captured
json data.
"""
with utils.ChangeDir(self.dirname):
command_list = ['PYTHONPATH=' + main_dir, interpreter,
self.filename] + list(self.args)
try:
proc = Popen(' '.join(command_list), stdout=PIPE, stderr=PIPE,
shell=True)
stream_data = proc.communicate()
except Exception as e:
logger.error(
"Error {0} while executing extract_dist command.".format(e))
raise ExtractionError
stream_data = [utils.console_to_str(s) for s in stream_data]
if proc.returncode:
logger.error(
"Subprocess failed, stdout: {0[0]}, stderr: {0[1]}".format(
stream_data))
self._result = json.loads(stream_data[0].split(
"extracted json data:\n")[-1].split("\n")[0])
def run(self, interpreter):
"""Executes the code of the specified module. Deserializes captured
json data.
"""
with utils.ChangeDir(self.dirname):
command_list = ['PYTHONPATH=' + main_dir, interpreter,
self.filename] + list(self.args)
try:
proc = Popen(' '.join(command_list), stdout=PIPE, stderr=PIPE,
shell=True)
stream_data = proc.communicate()
except Exception as e:
logger.error(
"Error {0} while executing extract_dist command.".format(e))
raise ExtractionError
stream_data = [utils.console_to_str(s) for s in stream_data]
if proc.returncode:
logger.error(
"Subprocess failed, stdout: {0[0]}, stderr: {0[1]}".format(
stream_data))
self._result = json.loads(stream_data[0].split(
'python-') else ''
spec_name = prefix + convertor.name + '.spec'
logger.info('Using name: {0} for specfile.'.format(spec_name))
if d == settings.DEFAULT_PKG_SAVE_PATH:
# default save_path is rpmbuild tree so we want to save spec
# in rpmbuild/SPECS/
spec_path = d + '/SPECS/' + spec_name
else:
# if user provide save_path then save spec in provided path
spec_path = d + '/' + spec_name
spec_dir = os.path.dirname(spec_path)
if not os.path.exists(spec_dir):
os.makedirs(spec_dir)
logger.debug('Opening specfile: {0}.'.format(spec_path))
if not utils.PY3:
converted = converted.encode('utf-8')
with open(spec_path, 'w') as f:
f.write(converted)
logger.info('Specfile saved at: {0}.'.format(spec_path))
if srpm:
msg = utils.build_srpm(spec_path, d)
logger.info(msg)
else:
logger.debug('Printing specfile to stdout.')
if utils.PY3:
print(converted)
else:
print(converted.encode('utf-8'))
logger.debug('Specfile printed.')
def get_changelog_date_packager(self):
"""Returns part of the changelog entry, containing date and packager.
"""
try:
packager = subprocess.Popen(
'rpmdev-packager', stdout=subprocess.PIPE).communicate(
)[0].strip()
except OSError:
# Hi John Doe, you should install rpmdevtools
packager = "John Doe "
logger.warn("Package rpmdevtools is missing, using default "
"name: {0}.".format(packager))
with utils.c_time_locale():
date_str = time.strftime('%a %b %d %Y', time.gmtime())
encoding = locale.getpreferredencoding()
return u'{0} {1}'.format(date_str, packager.decode(encoding))
def __setattr__(self, name, value):
if name == 'summary' and isinstance(value, utils.str_classes):
value = value.rstrip('.').replace('\n', ' ')
if value is not None:
self.data[name] = value