Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cursor.execute('SELECT * FROM host')
rows = cursor.fetchall()
plength = len(rows)
pbar = progress_bar('Hosts', plength)
i = 0
for row in rows:
pbar.update(i+1)
i += 1
host, created = Host.objects.get_or_create(
hostname=row['host'],
id=row['id'],
arch=MachineArchitecture.objects.get(id=row['arch_id']),
defaults={
'ipaddress': row['report_ip'],
'os': OS.objects.get(id=row['os_id']),
'domain': Domain.objects.get(id=row['dmn_id']),
'lastreport': row['pkgs_change_timestamp'],
},
tag=row['admin'],
kernel=row['kernel']
)
cursor.close()
def import_repos(conn):
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT * FROM repositories')
rows = cursor.fetchall()
plength = len(rows)
pbar = progress_bar('Repositories', plength)
i = 0
for row in rows:
repo, c = Repository.objects.get_or_create(
id=row['id'], name=row['name'], url=row['url'], security=row['is_sec'], enabled=row['enabled'],last_access_ok=row['last_access_ok'], file_checksum=row['file_checksum'], timestamp=row['timestamp'], arch=MachineArchitecture.objects.get(id=row['arch_id']))
if row['type'] == "dpkg":
repotype="D"
elif row['type'] == "rpm":
repotype="R"
repo.repotype = repotype
repo.save()
pbar.update(i+1)
i += 1
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
cursor.execute('SELECT pkgs.name, act_version.arch, act_version.act_version, act_version.act_rel, repositories.id FROM (act_version inner join repositories on act_version.repo_id = repositories.id) inner join pkgs on act_version.pkg_id = pkgs.id')
rows = cursor.fetchall()
plength = len(rows)
pbar = progress_bar('Creating Package<->Repo Links', plength)
i = 0
for i, p in enumerate(parches):
a = PackageArchitecture.objects.get(name=p.name)
a.delete()
update_pbar(i + 1)
marches = MachineArchitecture.objects.filter(host__isnull=True,
repository__isnull=True)
mlen = marches.count()
if mlen == 0:
if verbose:
print 'No orphaned machine architectures found.'
else:
create_pbar('Removing {0!s} orphaned m arches:'.format(mlen), mlen)
for i, m in enumerate(marches):
a = MachineArchitecture.objects.get(name=m.name)
a.delete()
update_pbar(i + 1)