def main(sys_args): usage = "usage: %prog [-v|-verbose][-u|--unique][-s|--sort] path/to/Project.xcodeproj" description = "By default, without any option, xUnique uniquify and sort the project file." parser = OptionParser(usage=usage, description=description) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="output verbose messages. default is False.") parser.add_option("-u", "--unique", action="store_true", dest="unique_bool", default=False, help="uniquify the project file. default is False.") parser.add_option("-s", "--sort", action="store_true", dest="sort_bool", default=False, help="sort the project file. default is False.") (options, args) = parser.parse_args(sys_args[1:]) if len(args) < 1: parser.print_help() raise SystemExit("xUnique requires at least one positional argument: relative/absolute path to xcodeproj.") xcode_proj_path = args[0].decode(sys_get_fs_encoding()) xunique = XUnique(xcode_proj_path, options.verbose) if not (options.unique_bool or options.sort_bool): print("Uniquify and Sort") xunique.unique_pbxproj() print("Uniquify and Sort done") else: if options.unique_bool: print('Uniquify...') xunique.unique_project() if options.sort_bool: print('Sort...') xunique.sort_pbxproj()
def main(): rootPath = sys_argv[0].decode(sys_get_fs_encoding()) print 'RootPath\t', rootPath #檔案的絕對路徑 print 'path.abspath\t', path.abspath(rootPath) #檔案名稱 print 'path.basename\t', path.basename(rootPath) #檢查檔案是否存在 print 'path.exists\t', path.exists(rootPath) #取得檔案目錄位置 print 'path.dirname\t', path.dirname(rootPath) #分割出副檔名 print 'path.splitext\t', path.splitext(rootPath) #修改時間 print 'path.getatime\t', path.getatime(rootPath) #檔案大小 print 'path.getsize', path.getsize(rootPath) #路徑正規劃,正反斜線清除整理 print 'path.normcase', path.normcase(rootPath) #由後面路徑推敲出前面路徑的相對位置 print 'path.relpath', path.relpath(rootPath, path.dirname(rootPath)+'/../../') #檢查路徑下所有檔案 print 'path.walk(path, visit, arg)' for root, dirs, files in os.walk(path.dirname(rootPath)): print root for f in files: print os.path.join(root, f)
def pbxproj_to_json(self): pbproj_to_json_cmd = ['plutil', '-convert', 'json', '-o', '-', self.xcode_pbxproj_path] try: json_unicode_str = sp_co(pbproj_to_json_cmd).decode(sys_get_fs_encoding()) return json_loads(json_unicode_str) except CalledProcessError as cpe: raise XUniqueExit("""{} Please check: 1. You have installed Xcode Command Line Tools and command 'plutil' could be found in $PATH; 2. The project file is not broken, such like merge conflicts, incomplete content due to xUnique failure. """.format(cpe.output))
def main(): usage = "usage: %prog [-v][-u][-s][-c][-p] path/to/Project.xcodeproj" description = "Doc: https://github.com/truebit/xUnique" parser = OptionParser(usage=usage, description=description) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="output verbose messages. default is False.") parser.add_option("-u", "--unique", action="store_true", dest="unique_bool", default=False, help="uniquify the project file. default is False.") parser.add_option("-s", "--sort", action="store_true", dest="sort_bool", default=False, help="sort the project file. default is False. When neither '-u' nor '-s' option exists, xUnique will invisibly add both '-u' and '-s' in arguments") parser.add_option("-c", "--combine-commit", action="store_true", dest="combine_commit", default=False, help="When project file was modified, xUnique quit with non-zero status. Without this option, the status code would be zero if so. This option is usually used in Git hook to submit xUnique result combined with your original new commit.") parser.add_option("-p", "--sort-pbx-by-filename", action="store_true", dest="sort_pbx_fn_bool", default=False, help="sort PBXFileReference and PBXBuildFile sections in project file, ordered by file name. Without this option, ordered by MD5 digest, the same as Xcode does.") (options, args) = parser.parse_args(sys_argv[1:]) if len(args) < 1: parser.print_help() raise XUniqueExit( "xUnique requires at least one positional argument: relative/absolute path to xcodeproj.") xcode_proj_path = args[0].decode(sys_get_fs_encoding()) xunique = XUnique(xcode_proj_path, options.verbose) if not (options.unique_bool or options.sort_bool): print_ng("Uniquify and Sort") xunique.unique_project() xunique.sort_pbxproj(options.sort_pbx_fn_bool) success_print("Uniquify and Sort done") else: if options.unique_bool: print_ng('Uniquify...') xunique.unique_project() if options.sort_bool: print_ng('Sort...') xunique.sort_pbxproj(options.sort_pbx_fn_bool) if options.combine_commit: if xunique.is_modified: raise XUniqueExit("File 'project.pbxproj' was modified, please add it and then commit.") else: if xunique.is_modified: warning_print( "File 'project.pbxproj' was modified, please add it and commit again to submit xUnique result.\nNOTICE: If you want to submit xUnique result combined with original commit, use option '-c' in command.")
def main(sys_args): usage = "usage: %prog [-v][-u][-s][-c][-p] path/to/Project.xcodeproj" description = "When neither '-u' nor '-s' option exists, xUnique will invisibly add both '-u' and '-s' in arguments" parser = OptionParser(usage=usage, description=description) parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="output verbose messages. default is False.") parser.add_option("-u", "--unique", action="store_true", dest="unique_bool", default=False, help="uniquify the project file. default is False.") parser.add_option("-s", "--sort", action="store_true", dest="sort_bool", default=False, help="sort the project file. default is False.") parser.add_option("-c", "--combine-commit", action="store_true", dest="combine_commit", default=False, help="When project file was modified, xUnique quit with non-zero status. Without this option, the status code would be zero if so. This option is usually used in Git hook to submit xUnique result combined with your original new commit.") parser.add_option("-p", "--sort-pbx-by-filename", action="store_true", dest="sort_pbx_fn_bool", default=False, help="sort PBXFileReference and PBXBuildFile sections in project file, ordered by file name. Without this option, ordered by MD5 digest, the same as Xcode does.") (options, args) = parser.parse_args(sys_args[1:]) if len(args) < 1: parser.print_help() raise XUniqueExit( "xUnique requires at least one positional argument: relative/absolute path to xcodeproj.") xcode_proj_path = args[0].decode(sys_get_fs_encoding()) xunique = XUnique(xcode_proj_path, options.verbose) if not (options.unique_bool or options.sort_bool): print_ng("Uniquify and Sort") xunique.unique_project() xunique.sort_pbxproj(options.sort_pbx_fn_bool) success_print("Uniquify and Sort done") else: if options.unique_bool: print_ng('Uniquify...') xunique.unique_project() if options.sort_bool: print_ng('Sort...') xunique.sort_pbxproj(options.sort_pbx_fn_bool) if options.combine_commit: if xunique.is_modified: raise XUniqueExit("File 'project.pbxproj' was modified, please add it and then commit.") else: if xunique.is_modified: warning_print("File 'project.pbxproj' was modified, please add it and commit again to submit xUnique result.\nNOTICE: If you want to submit xUnique result combined with original commit, use option '-c' in command.")
from __future__ import print_function from subprocess import (check_output as sp_co, CalledProcessError) from os import path, unlink, rename from hashlib import md5 as hl_md5 from json import (loads as json_loads, dump as json_dump) from fileinput import (input as fi_input, close as fi_close) from re import compile as re_compile from sys import (argv as sys_argv, getfilesystemencoding as sys_get_fs_encoding) from collections import deque from filecmp import cmp as filecmp_cmp from optparse import OptionParser md5_hex = lambda a_str: hl_md5(a_str.encode('utf-8')).hexdigest().upper() print_ng = lambda *args, **kwargs: print( *[unicode(i).encode(sys_get_fs_encoding()) for i in args], **kwargs) # output_u8line = lambda a_unicode: print(a_unicode.encode('utf-8'), end='') output_u8line = lambda *args: print( *[unicode(i).encode('utf-8') for i in args], end='') def warning_print(*args, **kwargs): new_args = list(args) new_args[0] = '\x1B[33m{}'.format(new_args[0]) new_args[-1] = '{}\x1B[0m'.format(new_args[-1]) print_ng(*new_args, **kwargs) def success_print(*args, **kwargs): new_args = list(args) new_args[0] = '\x1B[32m{}'.format(new_args[0])
from __future__ import unicode_literals from __future__ import print_function from subprocess import (check_output as sp_co, CalledProcessError) from os import path, unlink, rename from hashlib import md5 as hl_md5 from json import (loads as json_loads, dump as json_dump) from fileinput import (input as fi_input, close as fi_close) from re import compile as re_compile from sys import (argv as sys_argv, getfilesystemencoding as sys_get_fs_encoding) from collections import deque from filecmp import cmp as filecmp_cmp from optparse import OptionParser md5_hex = lambda a_str: hl_md5(a_str.encode('utf-8')).hexdigest().upper() print_ng = lambda *args, **kwargs: print(*[unicode(i).encode(sys_get_fs_encoding()) for i in args], **kwargs) #output_u8line = lambda a_unicode: print(a_unicode.encode('utf-8'), end='') output_u8line = lambda *args : print(*[unicode(i).encode('utf-8') for i in args],end='') def warning_print(*args, **kwargs): new_args = list(args) new_args[0] = '\x1B[33m{}'.format(new_args[0]) new_args[-1] = '{}\x1B[0m'.format(new_args[-1]) print_ng(*new_args, **kwargs) def success_print(*args, **kwargs): new_args = list(args) new_args[0] = '\x1B[32m{}'.format(new_args[0]) new_args[-1] = '{}\x1B[0m'.format(new_args[-1]) print_ng(*new_args, **kwargs)
def decoded_string(string, encoding=None): if isinstance(string, six.text_type): return string return string.decode(encoding or sys_get_fs_encoding())
string_types = (basestring,) return SixPython2Impl else: raise XUniqueExit("unsupported python version") six = construct_compatibility_layer() # 将指定字符串以UTF-8编码后得到其大写的MD5编码。 md5_hex = lambda a_str: hl_md5(a_str.encode('utf-8')).hexdigest().upper() # print_ng: 以系统字符集输出。 # output_u8line: 以UTF-8字符集输出。 if six.PY2: print_ng = lambda *args, **kwargs: print(*[six.text_type(i).encode(sys_get_fs_encoding()) for i in args], **kwargs) output_u8line = lambda *args: print(*[six.text_type(i).encode('utf-8') for i in args], end='') elif six.PY3: print_ng = lambda *args, **kwargs: print(*args, **kwargs) output_u8line = lambda *args: print(*args, end='') else: assert false # 解码成当前版本Python使用的字符串。 def decoded_string(string, encoding=None): if isinstance(string, six.text_type): return string return string.decode(encoding or sys_get_fs_encoding())
def pbxproj_to_json(self): pbproj_to_json_cmd = ['plutil', '-convert', 'json', '-o', '-', self.xcode_pbxproj_path] json_unicode_str = sp_co(pbproj_to_json_cmd).decode(sys_get_fs_encoding()) return json_loads(json_unicode_str)
PY2 = True PY3 = False text_type = unicode string_types = (basestring, ) return SixPython2Impl else: raise XUniqueExit("unsupported python version") six = construct_compatibility_layer() md5_hex = lambda a_str: hl_md5(a_str.encode('utf-8')).hexdigest().upper() if six.PY2: print_ng = lambda *args, **kwargs: print( *[six.text_type(i).encode(sys_get_fs_encoding()) for i in args], **kwargs) output_u8line = lambda *args: print( *[six.text_type(i).encode('utf-8') for i in args], end='') elif six.PY3: print_ng = lambda *args, **kwargs: print(*args, **kwargs) output_u8line = lambda *args: print(*args, end='') def decoded_string(string, encoding=None): if isinstance(string, six.text_type): return string return string.decode(encoding or sys_get_fs_encoding()) def warning_print(*args, **kwargs):
class SixPython2Impl(object): PY2 = True PY3 = False text_type = unicode string_types = (basestring,) return SixPython2Impl else: raise RuntimeError("unsupported python version") six = construct_compatibility_layer() md5_hex = lambda a_str: hl_md5(a_str.encode('utf-8')).hexdigest().upper() if six.PY2: print_ng = lambda *args, **kwargs: print(*[six.text_type(i).encode(sys_get_fs_encoding()) for i in args], **kwargs) output_u8line = lambda *args: print(*[six.text_type(i).encode('utf-8') for i in args], end='') elif six.PY3: print_ng = lambda *args, **kwargs: print(*args, **kwargs) output_u8line = lambda *args: print(*args, end='') def decoded_string(string, encoding=None): if isinstance(string, six.text_type): return string return string.decode(encoding or sys_get_fs_encoding()) def warning_print(*args, **kwargs): new_args = list(args) new_args[0] = '\x1B[33m{}'.format(new_args[0])