2013-04-07 09:16:23 -03:00
|
|
|
#! /usr/bin/python3
|
2013-03-31 14:31:33 -03:00
|
|
|
# -*- coding:utf-8 -*-
|
|
|
|
|
|
|
|
# i18n
|
|
|
|
import gettext
|
|
|
|
gettext.bindtextdomain('pamac', '/usr/share/locale')
|
|
|
|
gettext.textdomain('pamac')
|
|
|
|
_ = gettext.gettext
|
2013-01-16 15:09:52 -03:00
|
|
|
|
|
|
|
def format_size(size):
|
|
|
|
KiB_size = size / 1024
|
|
|
|
if KiB_size < 1000:
|
2013-03-31 14:31:33 -03:00
|
|
|
size_string = _('%.1f KiB') % (KiB_size)
|
2013-01-16 15:09:52 -03:00
|
|
|
return size_string
|
|
|
|
else:
|
2013-03-31 14:31:33 -03:00
|
|
|
size_string = _('%.2f MiB') % (KiB_size / 1024)
|
2013-01-16 15:09:52 -03:00
|
|
|
return size_string
|
2013-01-30 14:37:41 -03:00
|
|
|
|
|
|
|
def format_pkg_name(name):
|
|
|
|
unwanted = ['>','<','=']
|
|
|
|
for i in unwanted:
|
|
|
|
index = name.find(i)
|
|
|
|
if index != -1:
|
|
|
|
name = name[0:index]
|
2013-02-11 11:45:24 -03:00
|
|
|
return name
|
2013-02-06 12:09:43 -03:00
|
|
|
|
2013-10-16 10:34:09 -03:00
|
|
|
from os.path import isfile, join
|
2013-02-10 11:59:53 -03:00
|
|
|
from os import getpid, remove
|
|
|
|
|
2013-10-16 10:34:09 -03:00
|
|
|
from pamac import config
|
|
|
|
|
2013-02-10 11:59:53 -03:00
|
|
|
pid_file = '/tmp/pamac.pid'
|
2013-10-16 10:34:09 -03:00
|
|
|
lock_file = join(config.pacman_conf.options['DBPath'], 'db.lck')
|
2013-02-10 11:59:53 -03:00
|
|
|
|
|
|
|
def pid_file_exists():
|
|
|
|
return isfile(pid_file)
|
|
|
|
|
|
|
|
def write_pid_file():
|
|
|
|
with open(pid_file, "w") as _file:
|
|
|
|
_file.write(str(getpid()))
|
|
|
|
|
|
|
|
def rm_pid_file():
|
|
|
|
if isfile(pid_file):
|
|
|
|
remove(pid_file)
|
2013-02-24 10:37:54 -03:00
|
|
|
|
2013-10-16 10:34:09 -03:00
|
|
|
def rm_lock_file():
|
|
|
|
if isfile(lock_file):
|
|
|
|
remove(lock_file)
|
|
|
|
|
2013-02-24 10:37:54 -03:00
|
|
|
import time
|
|
|
|
|
|
|
|
def write_log_file(string):
|
|
|
|
with open('/var/log/pamac.log', 'a') as logfile:
|
|
|
|
logfile.write(time.strftime('[%Y-%m-%d %H:%M]') + ' {}\n'.format(string))
|