Guest User

Untitled

a guest
Jul 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # updater.py
  5. #
  6. # Copyright 2009 Moises Henriquez <M0E.lnx [at] gmail [dot] com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 3 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. # MA 02110-1301, USA.
  22. """
  23. Vectorlinux update utilities
  24. """
  25. import os
  26. import subprocess
  27. import time
  28. import datetime
  29. import ConfigParser
  30.  
  31. __version__ = '0.1.2'
  32. __author__ = 'M0E-lnx'
  33. __credits__ = 'rbistolfi, lopz, Uelsk8s'
  34.  
  35. if os.path.exists('/etc/vlupdater.conf'):
  36. conf = ConfigParser.ConfigParser()
  37. conf.read('/etc/vlupdater.conf')
  38. tmpdir = conf.get('general', 'cachedir')
  39. pkg_ext = conf.get('general', 'compression')
  40. else:
  41. tmpdir = '/tmp/vlupdater/'
  42. pkg_ext = 'tgz'
  43.  
  44. today = datetime.date.today().isoformat()
  45.  
  46.  
  47. class Package:
  48. '''
  49. Returns a new package object
  50.  
  51. Requires one argument. A path to a package file in /var/log/packages
  52. '''
  53. def __init__(self, path):
  54. self.pkgname = os.path.split(path)[-1]
  55. sp = self.pkgname.rsplit('-', 3)
  56. self.appname = sp[0]
  57. self.version = sp[1]
  58. f = open(path, 'r')
  59. self.data = f.readlines()
  60. f.close()
  61.  
  62. def _pull_description(self):
  63. '''
  64. Re-generates the slack-desc file by parsing self.data
  65. '''
  66. res = []
  67. n = self.data.index('./\n')
  68. i = 0
  69. while i <= n:
  70. if self.data[i][:len(self.appname)] == self.appname:
  71. res.append(self.data[i].strip())
  72. i += 1
  73. return '\n'.join(res) + '\n'
  74. def _pull_install_script(self):
  75.  
  76. '''
  77. Re-generates the doinst.sh file by parsing the script file
  78. '''
  79. scriptsloc = '/var/log/scripts/'
  80. if os.path.exists(os.path.join(scriptsloc, self.pkgname)) == False:
  81. return None
  82. else:
  83. out = []
  84. f = open(os.path.join(scriptsloc, self.pkgname), 'r')
  85. for i in f.readlines():
  86. out.append(i.strip())
  87. f.close
  88. return '\n'.join(out) + '\n'
  89. def _do_cmd(self, cmd):
  90. return subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, \
  91. stderr=subprocess.STDOUT, shell=True)
  92. def repackage(self):
  93. '''
  94. Re-creates the package based on the information provided by self.data
  95. '''
  96. n = self.data.index('./\n')
  97. tmp_pkg = os.path.join(tmpdir, today, 'pkg-%s' %(self.appname))
  98. for i in range(n, len(self.data)):
  99. if 'install/' in self.data[i].strip():
  100. print "I got install"
  101. pass
  102. if self.data[i].strip() == None:
  103. pass
  104. if self.data[i].strip()[-1] == '/':
  105. com = 'mkdir -p %s' % (os.path.join(tmp_pkg, self.data[i].strip()))
  106. else:
  107. com = 'cp -arp %s %s' % ('/' + self.data[i].strip(), \
  108. os.path.join(tmp_pkg, self.data[i].strip()))
  109. print com
Add Comment
Please, Sign In to add comment