metadata.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/python3
  2. ## script to get metadata from debsources database and/or other sources
  3. ## returns list of sloc for languages in the form [ansic (C), cpp (C++), asm (assembly),
  4. ## java, python, perl, shell script)]
  5. ## We can take into account any additional languages
  6. ## tries to take the latest version of the package into account (does this make sense?)
  7. def fixName(pkg_name):
  8. if pkg_name == 'firefox':
  9. return 'iceweasel'
  10. else:
  11. return pkg_name
  12. def getsloccount(cur, pkg_name):
  13. pkg_name = fixName(pkg_name)
  14. querry = "SELECT SUM(int_value), st_value FROM metrics WHERE metric_info_id = 'sloccount' AND file_id IN (SELECT file_id from paths WHERE package_id = (SELECT package_id from package_info WHERE package_version = (SELECT MAX(package_version) FROM package_info WHERE package_name = '" + pkg_name + "') AND package_name = '" + pkg_name + "')) GROUP BY st_value ORDER BY st_value;"
  15. cur.execute(querry)
  16. rows = cur.fetchall()
  17. sloc = [0, 0, 0, 0, 0, 0, 0]
  18. total = 0
  19. for row in rows:
  20. total += row[0]
  21. if row[1] == 'ansic':
  22. sloc[0] = row[0]
  23. elif row[1] == 'cpp':
  24. sloc[1] = row[0]
  25. elif row[1] == 'asm':
  26. sloc[2] = row[0]
  27. elif row[1] == 'java':
  28. sloc[3] = row[0]
  29. elif row[1] == 'python':
  30. sloc[4] = row[0]
  31. elif row[1] == 'perl':
  32. sloc[5] = row[0]
  33. elif row[1] == 'sh':
  34. sloc[6] = row[0]
  35. return (total, sloc)
  36. if __name__ == "__main__":
  37. sloc = []
  38. total = 0
  39. (total, sloc) = getsloccount('less')
  40. print(total)
  41. print(sloc)