###############################################################################
import os
-import random
import shutil
-import string
-import sys
-import time
-
-import logging
-log = logging.getLogger("pakfire")
-
-from .constants import *
-from .i18n import _
-
-def cli_is_interactive():
- """
- Say weather a shell is interactive or not.
- """
- if sys.stdin.isatty() and sys.stdout.isatty() and sys.stderr.isatty():
- return True
-
- return False
-
-def random_string(length=20):
- s = ""
-
- for i in range(length):
- s += random.choice(string.ascii_letters)
-
- return s
-
-def make_progress(message, maxval, eta=True, speed=False):
- # XXX delay importing the progressbar module
- # (because of a circular dependency)
- from .ui import progressbar
-
- # Return nothing if stdout is not a terminal.
- if not sys.stdout.isatty():
- return
-
- if not maxval:
- maxval = 1
-
- pb = progressbar.ProgressBar(maxval)
- pb.add("%-50s" % message)
-
- bar = progressbar.WidgetBar()
- pb.add(bar)
-
- if speed:
- percentage = progressbar.WidgetPercentage()
- pb.add(percentage)
-
- filetransfer = progressbar.WidgetFileTransferSpeed()
- pb.add(filetransfer)
-
- if eta:
- eta = progressbar.WidgetETA()
- pb.add(eta)
-
- return pb.start()
def rm(path, *args, **kargs):
"""
os.system("chattr -R -i %s" % path)
else:
raise
-
-def text_wrap(s, length=65):
- if not s:
- return ""
-
- lines = []
-
- words = []
- for line in s.splitlines():
- if not line:
- words.append("")
- else:
- words += line.split()
-
- line = []
- while words:
- word = words.pop(0)
-
- # An empty words means a line break.
- if not word:
- if line:
- lines.append(" ".join(line))
- lines.append("")
- line = []
-
- else:
- if len(" ".join(line)) + len(word) >= length:
- lines.append(" ".join(line))
- line = []
- words.insert(0, word)
- else:
- line.append(word)
-
- if line:
- lines.append(" ".join(line))
-
- assert not words
-
- #return "\n".join(lines)
- return lines