Ejemplo n.º 1
0
def main():
    parser = optparse.OptionParser(usage="cmd dev1@dir1 dir2")
    parser.add_option("--recursive", action="store_true")
    #parser.add_option("-q", "--quiet", action = "store_true", dest = "verbose",
    #default = False, help = "")
    (options, args) = parser.parse_args()

    Logger.set_level(0)

    if len(args) == 0:
        exit(0)

    assert len(args) == 2

    src_dir, port1 = replace_server(args[0])
    tgt_dir, port2 = replace_server(args[1])
    cmds = ["scp -oStrictHostKeyChecking=no"]

    if not nlp.is_none_or_empty(port1):
        cmds.append(f"-P {port1}")
    elif not nlp.is_none_or_empty(port2):
        cmds.append(f"-P {port2}")

    if options.recursive:
        cmds.append("-r")

    cmds.append(f"{src_dir} {tgt_dir}")

    nlp.execute_cmd(*cmds)
Ejemplo n.º 2
0
def main():
  parser = OptionParser(usage = "cmd [optons] kw1 kw2 ...]")
  #parser.add_option("-q", "--quiet", action = "store_true", dest = "verbose",
                     #default = False, help = "")
  parser.add_option("--dir_only", action="store_true", default=False)
  parser.add_option("--file_only", action="store_true", default=False)
  parser.add_option("--file_types", default="", help="such as py,cpp")
  parser.add_option("--global_search", action="store_true", default=False)
  parser.add_option("--reverse", action="store_true", default=False)
  parser.add_option("--sort_by_size", action="store_true", default=False)
  parser.add_option("--min_file_size", type=int, default=0,
                    help="default 0 Mb.")
  parser.add_option("--cmd", help='e.g., chmod a-w {}')
  (options, args) = parser.parse_args()

  args = [kw.lower() for kw in args]
  if options.file_types == "":
    file_types = set([])
  else:
    file_types = set(options.file_types.split(","))

  valid_files = []
  for f in get_files_or_folders(options.dir_only,
                                options.file_only,
                                file_types,
                                options.global_search):
    if ".git" in f or "/." in f:
      continue

    if not options.reverse and not include_all_keywords(f, args) or \
      options.reverse and include_all_keywords(f, args):
      continue

    file_size = os.path.getsize(f) / 1024 / 1024
    if file_size < options.min_file_size:
      continue

    cmd = options.cmd
    if not nlp.is_none_or_empty(cmd):
      cmd = cmd.replace("{}", f"'{f}'")
    else:
      cmd = None

    result = {
      "file": f,
      "file_size": file_size,
      "cmd": cmd
    }
    valid_files.append(result)

  valid_files.sort(key=lambda item: -item["file_size"])
  for file_id, item in enumerate(valid_files):
    print(f"{file_id:10}: {item['file_size']:.2f} Mb, {item['file']}")
    cmd = item["cmd"]
    if cmd is not None:
      nlp.execute_cmd(item["cmd"])
Ejemplo n.º 3
0
def apply_file_tag(item):
    fn, tag = item
    assert len(file2tags) > 0
    fn = normalize_file(fn)
    try:
        print("adding '%s' into '%s'" % (tag, fn))
        cmd = '''_tag_file -s "%s" "%s"''' % (tag, fn)
        nlp.execute_cmd(cmd)
    except:
        print("failed '%s'" % fn)
    print()
Ejemplo n.º 4
0
def main():
  parser = OptionParser(usage = "cmd [optons] file1 file2 ...]")
  #parser.add_option("-q", "--quiet", action = "store_true", dest = "verbose",
                     #default = False, help = "")
  (options, args) = parser.parse_args()

  for f in args:
    ext = nlp.get_file_extension(f)
    if ext.lower() == "mp4":
      Logger.warn(f"The input file '{f}' is already mp4 file.")
      continue

    new_f = nlp.replace_file_name(f, ext, "mp4")
    nlp.execute_cmd(f"ffmpeg -i {f} -q:a 0 -r 30 -strict -2 {new_f}")
Ejemplo n.º 5
0
def run_port(options, args):
  if options.search is not None:
    cmd = f"port search {options.search}"

  elif options.install is not None:
    cmd = f"sudo port install {options.install}"

  elif options.uninstall is not None:
    cmd = f"sudo port uninstall {options.uninstall}"

  elif options.update:
    cmd = f"sudo port update"

  elif options.list_installed:
    cmd = f"port list"

  nlp.execute_cmd(cmd)
Ejemplo n.º 6
0
def run_apt(options, args):
  if options.search is not None:
    cmd = f"apt search {options.search}"

  elif options.install is not None:
    cmd = f"sudo apt install {options.install}"

  elif options.uninstall is not None:
    cmd = f"sudo apt remove {options.uninstall}"

  elif options.update:
    cmd = f"sudo apt update"

  elif options.list_installed:
    cmd = f"apt list --installed"

  nlp.execute_cmd(cmd)
Ejemplo n.º 7
0
def run_pip(options, args):
  py = f"python{options.python}"
  assert py is not None

  if options.search is not None:
    cmd = f"{py} -m pip search {options.search}"

  elif options.install is not None:
    cmd = f"pip{options.python} install {options.install} --user {options.user}"

  elif options.uninstall is not None:
    cmd = f"sudo pip{options.python} uninstall {options.uninstall}"

  elif options.upgrade:
    cmd = f"sudo {py} -m pip install pip --upgrade"

  elif options.list_installed:
    cmd = f"{py} -m pip list"

  nlp.execute_cmd(cmd)
def main():
    parser = optparse.OptionParser(usage="cmd [optons]")
    parser.add_option("-d",
                      action="store_true",
                      dest="delete",
                      help="to delete additional files.")
    parser.add_option("--server",
                      default="ubuntu_wifi",
                      help="default 'ubuntu_wifi'")
    (options, args) = parser.parse_args()

    src_path = os.path.expanduser("~/inf")
    assert os.path.isdir(src_path)
    os.chdir(src_path)
    src_path = "."

    target_path = f"{options.server}@/media/ubuntu/backup/inf"

    cmd = f"_supdate.py {src_path} {target_path}"
    if options.delete:
        cmd += " -d"

    print("--" * 64)
    print(f"to delete   : {options.delete}")
    print()

    print(f"pwd: {os.getcwd()}")
    print(f"cmd to excute: {cmd}")

    print("--" * 64, "\n")

    answer = input("continue [y | n] ? >> ")
    if answer == "y":
        start_time = time.time()

        nlp.execute_cmd(f"chmod -Rv a+r *")
        nlp.execute_cmd("find . -type d -exec chmod -v a+rx {} \;")

        nlp.execute_cmd(cmd)

        nlp.execute_cmd("_clone_file_tag.py --cmd gen")

        duration = time.time() - start_time
        print(f"time: {duration} seconds.")
Ejemplo n.º 9
0
                     #default = False, help = "")
  parser.add_option("--exclude", dest="excludePattern", default=None)
  parser.add_option("-d", action = "store_true", dest = "delete",
                    default = False)
  (options, args) = parser.parse_args()
  assert len(args) == 2 and ("." == args[0] or "." == args[1])

  Logger.set_level(0)
  deleteOpt = "--delete" if options.delete else ""
  if options.excludePattern is not None:
    excludeOpt = f"--exclude={options.excludePattern}"
  else:   
    excludeOpt = ""

  srcDir, port1 = _scp.replace_server(args[0])
  tgtDir, port2 = _scp.replace_server(args[1])
  srcDir += "/"
  tgtDir += "/"

  if not nlp.is_none_or_empty(port1):
    port_opt = f"--port={port1}"
  elif not nlp.is_none_or_empty(port2):
    port_opt = f"--port={port2}"
  else:
    port_opt = ""

  cmd = f"rsync -ravutzhlog --progress -e ssh {port_opt} " \
        f"{srcDir} {tgtDir} {excludeOpt} {deleteOpt}"
  nlp.execute_cmd(cmd)

Ejemplo n.º 10
0
#!/usr/bin/env python3
#coding: utf8

from palframe import nlp
import optparse
import os

if __name__ == "__main__":
    parser = optparse.OptionParser(usage="cmd server 'cmd'")
    #parser.add_option("-q", "--quiet", action = "store_true", dest = "verbose",
    #default = False, help = "")
    (options, args) = parser.parse_args()

    os.chdir("/Library/Preferences/SystemConfiguration")
    nlp.execute_cmd("sudo rm -v com.apple.airport.preferences.plist")
    nlp.execute_cmd("sudo rm -v NetworkInterfaces.plist")
    nlp.execute_cmd("sudo rm -v preferences.plist")
#!/usr/bin/env python3

from palframe import nlp
from palframe import *

if __name__ == "__main__":
    parser = OptionParser(usage="cmd [optons] ..]")
    #parser.add_option("-q", "--quiet", action = "store_true", dest = "verbose", \
    #default = False, help = "don't print status messages to stdout")
    parser.add_option("-t",
                      "--time",
                      dest="timeLength",
                      type="int",
                      default=10,
                      help="10s by default")
    (options, args) = parser.parse_args()

    assert options.timeLength > 0

    os.chdir(os.path.expanduser("~/Library/Preferences"))
    nlp.execute_cmd(
        "defaults write org.niltsh.MPlayerX SeekStepTimeL -float -%d" %
        options.timeLength)
    nlp.execute_cmd(
        "defaults write org.niltsh.MPlayerX SeekStepTimeR -float %d" %
        options.timeLength)