Example #1
0
def main(args=None):
    if not args:
        args = get_input_args('l:y:k:e')
    if args:
        src_path = None
        src_enc = False
        key = None
        bdy_args = {'-f': '.md', '-v': None, '-c': 'upload'}
        for k, v in args.items():
            if v:
                v = v if isinstance(v, str) else v[0]
            if k == '-l':  # local path
                src_path = os.path.abspath(v)
                bdy_args["-l"] = src_path
            elif k == '-y':  # yun path.
                bdy_args['-y'] = v
            elif k == '-k':
                key = v
            elif k == '-e':  # encrypto
                src_enc = True
        if any(('-l' not in bdy_args, '-y' not in bdy_args)):
            print("Pls set -l and -y")
            return False
        if bdy_args:
            if src_enc:  # decrypto, upload and encrypto
                if crypto_markdown(src_path, key, False):  # decrypto files.
                    BaiduYun(view=True).main(bdy_args)  # upload to baiduyun.
                    crypto_markdown(src_path, key, True)  # re-encrypto.
                else:  # error
                    print('error, decrypto failed!')
                    return False
            else:  # upload to yun.
                BaiduYun(view=True).main(bdy_args)  # upload to baiduyun.
    return True
Example #2
0
def get_face_image():
    fid = None
    sid = None
    args = get_input_args('hf:s:')
    for k in args.keys():
        if k == '-f':
            fid = get_abs_path(args['-f'])
        elif k == '-s':
            sid = get_abs_path(args['-s'])
        elif k == '-h':
            print_help(HELP_MENU)
    return fid, sid
Example #3
0
 def main(self, args=None):
     if not args:
         args = pyinput.get_input_args('dDeEk:s:o:c:m:t:rvh')
     if args:
         # set vars.
         global key, src, dst, cipher, mode, ftype, xtype, rtype
         pr = False
         opts = []
         for k, v in args.items():
             if k == '-k':
                 key = v
             elif k == '-s':
                 src = os.path.abspath(v)
             elif k == '-o':
                 dst = os.path.abspath(v)
             elif k == '-c':
                 if len(v) < 2:
                     cipher = v
                 else:
                     cipher = v[0]
                     mode = v[1]
             elif k == '-m':
                 mode = v
             elif k == '-t':
                 ftype = v
             elif k == '-x':
                 xtype = v
             elif k == '-v':
                 pr = True
             elif k == '-r':
                 rtype = True
             elif k in ['-d', '-D', '-e', '-E']:
                 opts.append(k)
                 if k in ['-d', '-e']:  # remove ftype files.
                     rtype = True
             elif k == '-h':
                 self.cryptofile_help()
         # set dst = src if src is None.
         if not dst:
             dst = src
         if opts:
             cf = cryptofile.CryptoFile(key, src, dst, ftype, xtype, cipher,
                                        mode)
             cf.set_pr(pr)
             # run opts.
             for opt in opts:
                 if opt in ['-d', '-D']:
                     if all((cf.decrypto_files(), rtype)):
                         pyfile.remove_type_file(src, ftype)
                 elif opt in ['-e', '-E']:
                     if all((cf.encrypto_files(), rtype)):
                         pyfile.remove_type_file(src, ftype)
Example #4
0
def markdown(args=None):
    key = None
    key_file_path = None
    src = os.getcwd()
    dst = src
    opts = []
    if not args:
        args = pyinput.get_input_args('dek:f:s:o:h')
        if not args:
            markdown_help()
            exit()
    # set vars.
    for k, v in args.items():
        if v:  # transfer v.
            v = v if type(v) == str else v[0]
        if k == '-k':  # key
            key = v
        elif k == '-f':  # key file.
            key_file_path = os.path.abspath(v)
        elif k == '-s':  # path of source.
            src = os.path.abspath(v)
            dst = src
        elif k == '-o':  # path of output.
            dst = os.path.abspath(v)
        elif k == '-d':  # decrypto.
            opts.append(k)
        elif k == '-e':  # encrypto.
            opts.append(k)
        else:
            markdown_help()
    if not opts:
        return True
    # get key.
    if not key:
        # get key from md5 key file.
        key = cryptokey.get_key_form_file(key_file_path)
        if not key:
            print('No found key!!!')
            return False
    # run opts.
    for opt in opts:
        if opt == '-d':  # decrypto.
            markdown_decrypto(key, src, dst)
        elif opt == '-e':  # encrypto.
            markdown_encrypto(key, src, dst)
    return True
Example #5
0
def main(args=None):
    if not args:
        args = get_input_args('u')
    if args:
        bdy_args = None
        for k in args.keys():
            if k == '-u':
                bdy_args = {
                    "-y": bdy_path,
                    "-l": loc_path,
                    "-f": ".md",
                    "-v": None,
                    "-c": "upload"
                }
        if bdy_args:
            if decrypto_files(loc_path):  # decrypto files.
                BaiduYun(view=True).main(bdy_args)  # upload to baiduyun.
                encrypto_files(loc_path)  # re-encrypto.
Example #6
0
 def main(self, args=None):
     passwd = key = None
     opts = dict()
     # check args.
     if not args:
         args = pyinput.get_input_args('w:k:c:r:h')
         if not args:
             self.print_usage()
             exit()
     if '-h' in args:
         self.print_usage()
         return True
     # process args
     for k, v in args.items():
         if v:
             v = v if isinstance(v, str) else v[0]
         # check opts.
         if k == '-w':  # passwd
             passwd = v
         elif k == '-k':  # key
             key = v
         elif k in ['-c', '-r']:
             opts[k] = v
         else:
             self.print_usage()
             exit()
     # process otps.
     for opt, path in opts.items():
         if opt == '-c':
             if any((not passwd, not key, not path)):
                 print('error, passwd or key error.', True)
             CryptoKey(passwd, key).set_passwd_key_to_file(path=path)
         elif opt == '-r':
             if path:
                 ckey = CryptoKey(passwd=passwd, key_path=path)
                 version, signature, build, others, cipher, mode, iv = ckey.get_key_file_info(path)
                 print("version   : {}".format(version))
                 print("signature : {}".format(signature))
                 print("build     : {}".format(build))
                 print("others    : {}".format(others))
                 print("cipher    : {}".format(cipher))
                 print("mode      : {}".format(mode))
                 key = ckey.get_key_from_file()
                 print('key       : {}'.format(key if key else 'error'))
Example #7
0
File: ibus.py Project: SanniZ/ByPy
 def main(self):
     args = get_input_args('harLPpgSBbu', True)
     if not args:
         print_help(self.HELP_MENU)
         sys.exit()
     else:
         for k in args.keys():
             if k == '-a':
                 self.ibus_add_to_wubi_love98_db()
             elif k == '-u':
                 self.ibus_update_wubi_love98_db()
             elif k == '-r':
                 self.ibus_restart()
             elif k == '-L':
                 rescode, data = self.ibus_list_engine()
                 if rescode < 0:
                     print('error, failed to get engine list.')
                 else:
                     print(str(data, 'utf-8').strip('\n'))
             elif k == '-P':
                 self.ibus_set('sunpinyin')
             elif k == '-p':
                 self.ibus_set('pinyin')
             elif k == '-g':
                 self.ibus_set('googlepinyin')
             elif k == '-w':
                 self.ibus_set('wubi98')
             elif k == '-S':
                 self.ibus_setup()
             elif k == '-B':
                 self.ibus_set('wubi-haifeng86')
             elif k == '-b':
                 self.ibus_set('wubi-jingdian86')
             elif k == '-h':
                 print_help(self.HELP_MENU)
                 sys.exit()
             else:
                 print_help(self.HELP_MENU)
                 sys.exit()
Example #8
0
 def get_input(self):
     args = get_input_args('hs:t:v')
     for k in args.keys():
         # src path
         if k == '-s':
             self._src = get_abs_path(args['-s'])
         # dst path
         elif k == '-t':
             self._dst = get_abs_path(args['-t'])
         # show
         elif k == '-v':
             self._show = True
         elif k == '-h':
             print_help(self.HELP_MENU)
     # start to check args.
     # start id is must be set, otherwise return..
     if not self._src:
         return False
     # next to start if _end is not set.
     if not self._dst:
         self._dst = get_current_path()
         print('warnning: no found -t, output to: %s' % self._dst)
     return True
Example #9
0
 def get_user_opt(self):
     args = get_input_args('hcf:r:s:t:')
     for k in args.keys():
         if k == r'-h':
             print_help(self.HELP_MENU)
         elif k == r'-c':
             self._combine_files = True
         elif k == r'-f':
             fmt = args['-f'].lower()
             if fmt == TYPE_TXT or fmt == TYPE_CSV:
                 self._fmt = fmt
             else:
                 print_exit("Error, unsupport format!")
         elif k == r'-r':
             if args['-r'] == r'True':
                 self._sort_reverse = True
             else:
                 self._sort_reverse = False
         elif k == r'-s':
             # set _src to list
             if self._src is None:
                 self._src = list()
             # get src files
             fs = self.get_src_files(get_abs_path(args['-s']))
             if fs:
                 # add fs to _src
                 for f in fs:
                     self._src.append(f)
         elif k == r'-t':
             ftype = get_filetype(get_abs_path(args['-t']))
             if ftype in [TYPE_TXT, TYPE_CSV]:
                 self._tgt = get_abs_path(args['-t'])
                 self._combine_files = True
                 self._fmt = ftype
             else:
                 self._tgt = get_abs_path(args['-t'])
Example #10
0
File: mygit.py Project: SanniZ/ByPy
# entrance.
#
if __name__ == "__main__":
    from pybase.pyinput import get_input_args
    from pybase.pysys import print_help

    def mygit_help():
        HELPS = (
		"==============================================",
		"     mygit - %s" % VERSION,
		"==============================================",
		"Usage:  mygit option",
		"option:",
		"  -p : push origin master.",
		"  -m : check all of modified files.",
		"  -n : check all of new files",
        )
        print_help(HELPS, True)


    args = get_input_args('pmnh')
    if not args:
        mygit_help()
    for k in args.keys():
        if k == '-p': # sync to master
            mygit_push_origin_master()
        elif k in ['-m', '-n']: # check files.
            mygit_status(k)
        else:
            mygit_help()
Example #11
0
        '    rget: using requests to download file',
        '    uget: using urlopen to download file',
        '    html: download html of url',
        '  -v:',
        '    view info of webcontent.',
    )

    wc = WebContent()
    pr = PyPrint(wc.__class__.__name__)

    path = '%s/%s' % (get_download_path(), wc.__class__.__name__)
    url = None
    df = None
    view = False

    args = get_input_args('hp:u:d:v')
    for k in args.keys():
        if k == '-u':
            url = args['-u']
        elif k == '-v':
            view = True
            wc.pr.level = PR_LVL_ALL
        elif k == '-d':
            df_funcs = {
                'wget': wc.wget_url_file,
                'rtrv': wc.retrieve_url_file,
                'rget': wc.requests_get_url_file,
                'uget': wc.urlopen_get_url_file,
                'html': wc.get_url_content,
            }
            w = args[k]
Example #12
0
 def main(self, args=None):
     key = None
     key_file_path = None
     src = os.getcwd()
     dst = src
     opts = list()
     ftypes = list()
     # check args.
     if not args:
         args = pyinput.get_input_args('k:f:s::o:e:d:h')
         if not args:
             self.print_help_enum()
             return False
     # set vars.
     for k, v in args.items():
         if v:  # transfer v.
             v = v if isinstance(v, str) else v[0]
         if k == '-k':  # key
             key = v
         elif k == '-f':  # key file.
             key_file_path = os.path.abspath(v)
         elif k == '-s':  # path of source.
             if v:
                 src = os.path.abspath(v)
                 dst = src
         elif k == '-o':  # path of output.
             if v:
                 dst = os.path.abspath(v)
         elif k == '-d':  # decrypto.
             opts.append(k)
             if not v:
                 print("{} No ftype, -h for help".format(k))
                 return False
             ftypes = v.split(',')
         elif k == '-e':  # encrypto.
             opts.append(k)
             if not v:
                 print("{} No ftype, -h for help".format(k))
                 return False
             ftypes = v.split(',')
         elif k == '-h':  # help
             self.print_help_enum()
             exit()
         else:
             print("unknown {}, -h for help".format(k))
             # self.print_help_enum()
             exit()
     # check opts
     if not opts:
         self.print_help_enum()
         return False
     # check ftypes
     if not ftypes:
         print("No ftype, -h for help!")
         return False
     # get key.
     if not key:
         # get key from md5 key file.
         key = cryptokey.get_key_form_file(key_file_path)
         if not key:
             print('No found key!!!')
             return False
     # run opts.
     for opt in opts:
         if opt == '-d':  # decrypto.
             CryptoFileType(key, src, dst, ftypes).decrypto_files()
         elif opt == '-e':  # encrypto.
             CryptoFileType(key, src, dst, ftypes).encrypto_files()
     # exit
     return True
Example #13
0
        '    path  : path of dir or file',
        '    width : min of width',
        '    height: min of height',
        '  -R path: reclaim image format',
        '    path: path of dir or file',
        '  -o path,rename,nz: rename image to order',
        '    path  : path of images',
        '    rename: the format of image to be rename',
        '    nz    : True is set %0d, False is set %d',
        '  -i img: show detail info of image file',
        '    img: the path of image file.',
    )

    Img = PyImage()
    xval = None
    args = get_input_args('hc:r:R:x:o:i:')
    for k in args.keys():
        if k == '-c':
            result = Img.image_file(get_abs_path(args['-c']))
            print(result)
        elif k == '-r':
            data = args['-r'].split(',')
            path = data[0]
            if len(data) >= 3:
                w = data[1]
                h = data[2]
                Img.remove_small_image(path, int(w), int(h))
            else:
                Img.remove_small_image(path)
        elif k == '-R':
            path = args['-R']
Example #14
0
        '    ftype: file type will be find',
        '  -s path,wd,newd,ftype: sub wd with newd in path',
        '    path : path to dir or file',
        '    wd   : word will be find',
        '    newd : new word to replace wd',
        '    ftype: file type, example: txt',
        '  -c src,dst: copy files',
        '    src: path of source files.',
        '    dst: path to copy files',
        '  -m src,dst: move files',
        '    src: path of source files.',
        '    dst: path to copy files',
    )

    pr = PyPrint('PyFile')
    args = get_input_args('hr:f:s:c:m:', True)
    for k in args.keys():
        if k == '-r':
            remove_small_file(args['-r'])
        elif k == '-f':
            values = args['-f'].split(',')
            n = len(values)
            if n < 2:
                print_exit('input error, -h for help')
            elif any((not values[0], not values[1])):
                print_exit('input error, -h for help')
            # get args.
            path = get_abs_path(values[0])
            wd = values[1]
            if n == 2:
                result = find(path, wd)
Example #15
0
File: git.py Project: SanniZ/ByPy
#
# entrance
#
if __name__ == "__main__":
    from pybase.pyinput import get_input_args
    from pybase.pysys import print_help

    def git_help():
        HELPS = (
            "=================================================",
            "    git - %s" % VERSION,
            "=================================================",
            "Usage:    git.py options",
            "  options:",
            "    -p : push to master with 'git push origin master'",
            "    -m : get modified files of path.",
            "    -n : get new files of path.",
        )
        print_help(HELPS)

    args = get_input_args('p:m:n:h')
    if not args:
        git_help()
    for k, v in args.items():
        if k == '-p':
            git_push_origin_master(os.path.abspath(v))
        elif k in ['-m', '-n']:
            git_status(os.path.abspath(v), k, True)
        else:
            git_help()
Example #16
0
    from pybase.pyinput import get_input_args

    HELP_MENU = (
        '============================================',
        '    bakmypy - %s' % VERSION,
        '',
        '    @Author: %s' % AUTHOR,
        '    Copyright (c) %s studio' % AUTHOR,
        '============================================',
        'options:',
        ' -a: upload all of files to baiduyun.',
        ' -f: upload source files to baiduyun.',
        ' -z: tar files to mypy_(date-time).bz2 and upload to baiduyun.',
    )

    args = get_input_args('hafz', True)
    if args:
        date_ = time.strftime('%Y%m%d', time.localtime())
        time_ = time.strftime('%H%M', time.localtime())
        clean_cache(MYPYPATH)  # clear all of cache files.
        by = BaiduYun('BackupMypy')
        for k in args.keys():
            if k == '-a':
                args = {
                    '-c': 'upload',
                    '-l': MYPYPATH,
                    '-y': 'Mypy/%s/mypy_%s-%s_all' % (date_, date_, time_)
                }
                by.main(args)
            elif k == '-f':
                args = {
Example #17
0
        if fs:
            for f in fs:
                f = os.path.join(rt, f)
                if get_name_ex(f) == '.pyc':
                    os.remove(f)
                    if show:
                        print('remove: %s' % f)
            if dr:
                for d in dr:
                    if d == '__pycache__':
                        os.remove(d)


if __name__ == '__main__':
    show = False
    path = get_current_path()
    args = get_input_args('hp:vc')
    for k in args.keys():
        if k == '-p':
            if re.match('\.', args['-p']):
                path = re.sub('.', get_current_path(), args['-p'])
            else:
                path = args['-p']
        # check show.
        elif k == '-v':
            show = True
        elif k == '-h':
            print_help(HELP_MENU)
    # clean .pyc now.
    clean_pyc(path, show)
Example #18
0
                    self._thread_queue.put(url)
                    t.start()
                index += 1
            for t in threads:
                t.join()

    def main(self, args=None):
        args = self.process_input_args(OPTS + 'y:', args=args)
        if self._url_file:
            with open(self._url_file, 'r') as fd:
                urls = set(fd.readlines())
            self.process_list_input(urls, args)
        else:
            self.process_input(args)
        if self._search_urls:
            if '-x' in args:
                del args['-x']
            self.process_list_input(self._search_urls, args)
            self._search_urls = list()


if __name__ == '__main__':
    args = get_input_args('Uy:' + OPTS)
    if '-U' in args:
        from webimagecrawlerUI import WebImageCrawlerUI
        del args['-U']  # delete -U value.
        wc = WebImageCrawlerUI()
    else:
        wc = WebImageCrawler()
    wc.main(args)
Example #19
0
        print('==================================')
        print('    md5key - %s' % VERSION)
        print('==================================')
        print('usage: python3 md5key.py options')
        print('')
        print('options:')
        print(' -w passwd : set passwd')
        print(' -k key : set key')
        print(' -f path : create key file to path.')
        print(' -v path : display key of path file.')
        if exit_:
            exit()

    passwd = key = None
    opts = dict()
    args = get_input_args('w:k:f:v:h')
    if not args:
        print_usage(True)
    for k, v in args.items():
        if v:
            v = v if isinstance(v, str) else v[0]
        if k == '-w':
            passwd = v
        elif k == '-k':
            key = v
        elif k in ['-f', '-v']:
            opts[k] = v
        else:
            print_usage(True)
    for opt, path in opts.items():
        if opt == '-f':