def touch(path): """mkdir + touch path(s)""" for path in values.get(path): if path: path = _fullpath(path) _mkdir(path) _utime(path)
def init(fullname, sections): """init webhook from init file sections""" webhooks = ini2dict.read(GITHUB_WEBHOOKS_INI) for section in values.get(sections): url = webhooks[section]["url"] events = webhooks[section].get("events", "push").replace(" ", "").split(",") add(fullname, url, events=events)
def rm(path): """remove path(s) (if exists)""" for path in values.get(path): fullpath = os.path.abspath(os.path.expanduser(path)) if os.path.isfile(path) or os.path.islink(path): os.unlink(path) if os.path.isdir(fullpath): shutil.rmtree(fullpath)
def add(path): """add app to Dock""" data = mac_dock.preferences.read() for _path in values.get(path): d = {'tile-data': {'file-data': {'_CFURLString': _path, '_CFURLStringType': 0}}} if _path not in str(data["persistent-apps"]): data["persistent-apps"].append(d) mac_dock.preferences.write(data)
def load(self, path): """load sections and order""" for path in values.get(path): if os.path.exists(path) and os.path.isdir(path): self.load_sections(path) path = os.path.join(path, "order.txt") if os.path.exists(path): self.load_order(path)
def mktouch(path): """mkdir + touch""" for path in values.get(path): _mkdir(path) if not os.path.exists(path): open(path, "w").write("") else: _utime(path)
def rm(path, languages=None): """rm .localized/ lang files or .localized/ folder""" _localized = os.path.join(fullpath(path), ".localized") for lang in values.get(languages): f = os.path.join(_localized, "%s.strings" % lang) if os.path.exists(f): os.unlink(f) if not languages and os.path.exists(_localized): shutil.rmtree(_localized)
def load(path=".env"): """set environment variables from .env file""" if not path: path = ".env" for path in values.get(path): path = os.path.abspath(os.path.expanduser(path)) if not os.path.exists(path): raise OSError("%s NOT EXISTS" % path) os.environ.update(get(path))
def _args(query=None, name=None, onlyin=None): args = [] if name: args += ["-name", name] for path in values.get(onlyin): args += ["-onlyin", path] if query: args += [query] return list(args)
def rm(section, value): data = mac_dock.preferences.read() for value in list(set(values.get(value))): i = 0 for item_data in data[section]: if _eq(item_data, value): data[section].pop(i) continue i += 1 mac_dock.preferences.write(data)
def delete(fullname, webhooks): """delete repo webhooks by id or name or url""" data = github_webhooks.api.get(fullname) for webhook in values.get(webhooks): for hook in data: hook_id = hook["id"] name = hook["name"] url = hook["config"]["url"] if webhook == hook_id or webhook == name or webhook == url: github_webhooks.api.delete(fullname, hook_id)
def get(path=".env"): """return a dictionary wit .env file variables""" if not path: path = ".env" data = dict() for path in values.get(path): if not os.path.exists(path): raise OSError("%s NOT EXISTS" % os.path.abspath(path)) data.update(EnvFile(path)) return data
def close(urls): """close tabs with url(s)""" for url in values.get(urls): code = """ repeat with w in every window repeat with t in every tab in w if (URL of t) is ("%s" as text) then tell t to close end if end repeat end repeat""" % str(url) tell(code)
def add(fullname, url, events=["push"]): """add repo webhook""" if not events: events = ["push"] for hook in github_webhooks.api.get(fullname): if hook["config"]["url"] == url: return hook events = values.get(events) api_url = "https://api.github.com/repos/%s/hooks" % fullname config = dict(url=url, content_type="json") data = dict(name="web", active=True, events=events, config=config) return github_webhooks.api.request("POST", api_url, data).json()
def get(path): """return dictionary with path as key and tags as values""" args = ["-l"] + list(set(values.get(path))) out = _run(args) result = dict() for l in out.splitlines(): if "\t" in l: path, tags = l.split("\t") result[path] = tags.split(",") else: result[l] = [] return result
def load(self, path): """load sections and order""" for path in values.get(path): if not os.path.exists(path): raise OSError("%s NOT EXISTS" % path) if os.path.exists(path) and os.path.isdir(path): self.load_sections(path) f = os.path.join(path, "disabled.txt") if os.path.exists(f): self.load_disabled(f) f = os.path.join(path, "headers.json") if os.path.exists(f): self.load_headers(f) f = os.path.join(path, "order.txt") if os.path.exists(f): self.load_order(f)
def add(tags, path): """add tags to path(s)""" if path: run(["-a"] + _tags(tags) + values.get(path))
def open(urls): """open url(s)""" _run(["open"] + values.get(urls))
def find(tags, path=None): """return list of all paths with tags, limited to path(s) if present""" args = ["-f"] + _tags(tags) + values.get(path) out = run(args) return out.splitlines()
def get(path): """return dict where keys are paths, values are lists of tags. equivalent of `tag -l`""" args = ["-l"] + values.get(path) out = run(args) return parse_list_output(out)
def match(tags, path): """return list of paths with with matching tags""" args = ["-m"] + _tags(tags) + values.get(path) out = run(args) return out.splitlines()
def update(tags, path): """set path(s) tags. equivalent of `tag -s | --set`""" if path: run(["-s"] + _tags(tags) + values.get(path))
def remove(self, v): """remove element(s) by key""" for key in values.get(v): if key in self: self.pop(key) return self
def load(args): """`launchctl load args ...`""" subprocess.check_call(["/bin/launchctl", "load"] + values.get(args))
def run(args): """run `/usr/local/bin/tag` with arguments and return output""" if not os.path.exists(bin): raise OSError("%s NOT EXISTS\nrun `brew install tag`" % bin) return runcmd.run([bin] + values.get(args))._raise().out
def _kill_args(pid): return ["kill"] + list(map(str, values.get(pid)))
def refresh(urls): """refresh url(s)""" return _run(["refresh"] + values.get(urls))
def say(args, background=False): """run `say` with given args""" r = runcmd.run(["say"] + values.get(args), background=background) if not background: r._raise() return r
def mkdir(path): """mkdir (if not exists)""" for path in values.get(path): fullpath = os.path.expanduser(path) if fullpath and not os.path.exists(fullpath): os.makedirs(fullpath)
def remove(tags, path): """remove tags from path(s)""" tags = "*" if not tags else _tags(tags) if path: run(["-r"] + tags + values.get(path))