예제 #1
0
 def __init__(self, path, parser=None, autosave=True):
     self.path = fullpath(path)
     self.autosave = autosave
     if not parser:
         parser = RawConfigParser()
         path = fullpath(path)
         assert_exists(path)
         parser.read(path)
     self._parser = parser
예제 #2
0
def growlnotify(title=None, message=None, app=None,
                sticky=False, icon=None, image=None, url=None):
    if title and not isstring(title):
        title = str(title)
    if not message:
        message = ""
    if message and not isstring(message):
        message = str(message)
    # if message and isstring(message):
        # message = message.encode("utf-8")
    if title and title[0] == "-":
        title = "\\" + title
    # if title and isstring(title):
        # title = title.encode("utf-8")
    if not message and not title:
        title = ""
    args = []
    if title:
        args += ["-t", title]
    if app:
        args += ["-a", app]
    if icon:
        args += ["--icon", icon]
    if image:
        args += ["--image", fullpath(image)]
    if sticky:
        args += ["-s"]
    if url:
        args += ["--url", url]
    stdin = message
    # need first growlnotify arg for correct app icon
    args = ["growlnotify"] + args
    _open()
    _run(args, stdin)
예제 #3
0
def write(path, content):
    """write to file and return fullpath"""
    path = fullpath(path)
    if content is None:
        content = ""
    if isinstance(content, dict):
        content = json.dumps(content)
    if not isstring(content):
        content = str(content)
    if str(content.__class__) == "<class 'bytes'>":
        try:
            content = str(content, "utf-8")  # python3
        except TypeError:
            # TypeError: str() takes at most 1 argument (2 given)
            content = str(content)  # python2
    # if encoding:
        # content=content.encode(encoding)
    folder = os.path.dirname(path)
    if folder and not os.path.exists(folder):
        os.makedirs(folder)
    try:
        unicode()
        if isinstance(content, unicode):
            content = content.encode("utf-8")
        open(path, "w").write(content)
    except NameError:
        # NameError: name 'unicode' is not defined
        open(path, "w", encoding="utf-8").write(content)
    return path
예제 #4
0
def dirpath(path):
    """return directory path
    todo
    """
    if path is None:
        return None
    path = fullpath(path)
    if not cached(isdir)(path):
        assert_exists(path)
        path = dirname(path)
    return path
예제 #5
0
def touch(path):
    # todo: add datetime
    if not path:
        return
    path = fullpath(path)
    if path.find("/") > 0 and not os.path.exists(os.path.dirname(path)):
        os.makedirs(os.path.dirname(path))
    try:
        os.utime(path, None)
    except Exception:
        open(path, 'a').close()
예제 #6
0
def touch(path):
    if not path:
        return
    path = fullpath(path)
    _mkdir(path)
    _utime(path)
예제 #7
0
파일: dgit.py 프로젝트: ElectroCode/dgit
def get_repo(repo):
    click.echo('Repo selected: {} Path: {}'.format(repo,
                                                   fullpath.fullpath(repo)))
    Config.repo = git.Repo(repo)
    print(Config.repo)
예제 #8
0
 def __init__(self, path, read_only=False):
     self.read_only = read_only
     path = fullpath(path)
     parser = GitConfigParser(path, read_only=self.read_only)
     Conf.__init__(self, path=path, parser=parser)