Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # updater.py
- #
- # Copyright 2009 Moises Henriquez <M0E.lnx [at] gmail [dot] com>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- """
- Vectorlinux update utilities
- """
- import os
- import subprocess
- import time
- import datetime
- import ConfigParser
- __version__ = '0.1.2'
- __author__ = 'M0E-lnx'
- __credits__ = 'rbistolfi, lopz, Uelsk8s'
- if os.path.exists('/etc/vlupdater.conf'):
- conf = ConfigParser.ConfigParser()
- conf.read('/etc/vlupdater.conf')
- tmpdir = conf.get('general', 'cachedir')
- pkg_ext = conf.get('general', 'compression')
- else:
- tmpdir = '/tmp/vlupdater/'
- pkg_ext = 'tgz'
- today = datetime.date.today().isoformat()
- class Package:
- '''
- Returns a new package object
- Requires one argument. A path to a package file in /var/log/packages
- '''
- def __init__(self, path):
- self.pkgname = os.path.split(path)[-1]
- sp = self.pkgname.rsplit('-', 3)
- self.appname = sp[0]
- self.version = sp[1]
- f = open(path, 'r')
- self.data = f.readlines()
- f.close()
- def _pull_description(self):
- '''
- Re-generates the slack-desc file by parsing self.data
- '''
- res = []
- n = self.data.index('./\n')
- i = 0
- while i <= n:
- if self.data[i][:len(self.appname)] == self.appname:
- res.append(self.data[i].strip())
- i += 1
- return '\n'.join(res) + '\n'
- def _pull_install_script(self):
- '''
- Re-generates the doinst.sh file by parsing the script file
- '''
- scriptsloc = '/var/log/scripts/'
- if os.path.exists(os.path.join(scriptsloc, self.pkgname)) == False:
- return None
- else:
- out = []
- f = open(os.path.join(scriptsloc, self.pkgname), 'r')
- for i in f.readlines():
- out.append(i.strip())
- f.close
- return '\n'.join(out) + '\n'
- def _do_cmd(self, cmd):
- return subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, \
- stderr=subprocess.STDOUT, shell=True)
- def repackage(self):
- '''
- Re-creates the package based on the information provided by self.data
- '''
- n = self.data.index('./\n')
- tmp_pkg = os.path.join(tmpdir, today, 'pkg-%s' %(self.appname))
- for i in range(n, len(self.data)):
- if 'install/' in self.data[i].strip():
- print "I got install"
- pass
- if self.data[i].strip() == None:
- pass
- if self.data[i].strip()[-1] == '/':
- com = 'mkdir -p %s' % (os.path.join(tmp_pkg, self.data[i].strip()))
- else:
- com = 'cp -arp %s %s' % ('/' + self.data[i].strip(), \
- os.path.join(tmp_pkg, self.data[i].strip()))
- print com
Add Comment
Please, Sign In to add comment