Class: Milkode::Cdstk
- Inherits:
-
Object
- Object
- Milkode::Cdstk
- Defined in:
- lib/milkode/cdstk/cdstk.rb
Constant Summary collapse
- CONFIG_LJUST =
Parameters
20
- NAME =
'Name'
- TOTAL =
'Total'
Instance Method Summary collapse
- #add(dirs, options) ⇒ Object
- #add_dir(dir, no_yaml = false) ⇒ Object
- #add_yaml(package) ⇒ Object
- #assert_compatible ⇒ Object
- #breakdown_detail(records, name_width) ⇒ Object
- #breakdown_shorten(records) ⇒ Object
- #calc_percent(count, size) ⇒ Object
- #check_integrity ⇒ Object
- #cleanup(args, options) ⇒ Object
- #cleanup_all(options) ⇒ Object
-
#cleanup_packages ⇒ Object
Remove non exist pakcages.
- #cleanup_packages_in ⇒ Object
- #clear_count ⇒ Object
- #config(args, options) ⇒ Object
- #config_print ⇒ Object
- #config_set(args, options) ⇒ Object
-
#config_to_value(v) ⇒ Object
config_to_value(‘true’) #=> true config_to_value(‘false’) #=> false config_to_value(‘abc’) #=> ‘abc’.
- #convert_content(src, options) ⇒ Object
- #dir(args, options) ⇒ Object
- #download_file(src, options) ⇒ Object
- #download_file_in(url) ⇒ Object
- #dump ⇒ Object
- #extract_file(src) ⇒ Object
- #fav(args, options) ⇒ Object
- #files(args, options) ⇒ Object
- #find_package_current_dir ⇒ Object
-
#find_packages(args) ⇒ Object
引数が指定されている時は名前にマッチするパッケージを、未指定の時は現在位置から見つける.
- #git_clone_in(url, options) ⇒ Object
- #ignore(args, options) ⇒ Object
- #info(args, options) ⇒ Object
- #info_format(packages, format) ⇒ Object
- #info_format_breakdown(packages) ⇒ Object
- #info_format_detail(packages) ⇒ Object
- #info_format_table(packages) ⇒ Object
- #info_format_unknown(packages) ⇒ Object
- #init(options) ⇒ Object
-
#initialize(io = $stdout, db_dir = ".") ⇒ Cdstk
constructor
Display parameter for ‘milk config’.
- #linecount_total(records) ⇒ Object
- #list(args, options) ⇒ Object
- #mcd(options) ⇒ Object
- #package_records(name) ⇒ Object
- #pwd(options) ⇒ Object
- #rebuild(args, options) ⇒ Object
- #remove(args, options) ⇒ Object
- #remove_all ⇒ Object
- #select_format(options, default_value) ⇒ Object
- #set_yaml_options(package, options, is_update_with_git_pull, is_update_with_svn_update) ⇒ Object
- #setdb(args, options) ⇒ Object
- #sorted_plangs(records) ⇒ Object
- #svn_clone_in(url, options) ⇒ Object
- #update(args, options) ⇒ Object
- #update_all(options) ⇒ Object
- #update_for_grep(dir) ⇒ Object
- #yes_or_no(msg) ⇒ Object
Constructor Details
#initialize(io = $stdout, db_dir = ".") ⇒ Cdstk
Display parameter for ‘milk config’
37 38 39 40 41 42 43 44 |
# File 'lib/milkode/cdstk/cdstk.rb', line 37 def initialize(io = $stdout, db_dir = ".") @db_dir = db_dir @out = io # @out = $stdout # 強制出力 @is_display_info = false # alert_info の表示 clear_count @yaml = YamlFileWrapper.load_if(@db_dir) end |
Instance Method Details
#add(dirs, options) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/milkode/cdstk/cdstk.rb', line 119 def add(dirs, ) update_display_info() if [:from_file] dirs = File.read([:from_file]).split("\n") end print_result do # データベースを開く db_open # メイン処理 begin dirs.each do |v| # コンテンツを読み込める形に変換 dir = convert_content(v, ) # YAMLに追加 package = Package.create(dir, [:ignore]) skip_add = [:from_file] && @yaml.find_name(package.name) add_yaml(package) unless skip_add # オプション設定 is_update_with_git_pull = git_protocol?(, v) is_update_with_svn_update = svn_protocol?(, v) (package, , is_update_with_git_pull, is_update_with_svn_update) # アップデート unless [:empty] if skip_add update_package_in(package, ) else update_dir_in(dir) end end end rescue AddError => e error_alert(e.) return rescue ConvertError => e return end end end |
#add_dir(dir, no_yaml = false) ⇒ Object
202 203 204 205 206 |
# File 'lib/milkode/cdstk/cdstk.rb', line 202 def add_dir(dir, no_yaml = false) add_yaml(Package.create(dir)) unless no_yaml db_open update_dir_in(dir) end |
#add_yaml(package) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/milkode/cdstk/cdstk.rb', line 208 def add_yaml(package) # Already exist package if @yaml.find_name(package.name) raise AddError, "package named '#{package.name}' already exist." end # File not exist unless File.exist?(package.directory) raise AddError, "not found '#{package.directory}'." end # Save yaml @yaml.add(package) @yaml.save # Sync yaml -> db db_open @grndb.yaml_sync(@yaml.contents) end |
#assert_compatible ⇒ Object
65 66 67 |
# File 'lib/milkode/cdstk/cdstk.rb', line 65 def assert_compatible db_open end |
#breakdown_detail(records, name_width) ⇒ Object
921 922 923 924 925 926 |
# File 'lib/milkode/cdstk/cdstk.rb', line 921 def breakdown_detail(records, name_width) sorted_plangs(records).map {|name, count| percent = (count.to_f / records.size * 100).to_i sprintf("%-#{name_width}s %5d %3d%%", name, count, percent) }.join("\n") end |
#breakdown_shorten(records) ⇒ Object
895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 |
# File 'lib/milkode/cdstk/cdstk.rb', line 895 def breakdown_shorten(records) plangs = sorted_plangs(records) plangs = plangs.reduce([]) {|array, plang| name, count = plang percent = calc_percent(count, records.size) if percent == 0 if array.empty? || array[-1][0] != 'other' array << ['other', count] else array[-1][1] += count end else array << plang end array } plangs.map {|name, count| percent = calc_percent(count, records.size) "#{name}:#{count}(#{percent}%)" }.join(', ') end |
#calc_percent(count, size) ⇒ Object
891 892 893 |
# File 'lib/milkode/cdstk/cdstk.rb', line 891 def calc_percent(count, size) (count.to_f / size * 100).to_i end |
#check_integrity ⇒ Object
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/milkode/cdstk/cdstk.rb', line 483 def check_integrity db_open @out.puts "Check integrity ..." yaml = @yaml.contents.map {|p| p.name}.sort grndb = @grndb.packages.map {|p| p.name}.sort d = yaml.diff grndb unless d[0].empty? @out.puts "'milkode.yaml' has #{d[0]}, but 'PackageTable' don't have." end unless d[1].empty? @out.puts "'PackageTable' has #{d[1]}, but 'milkode.yaml' don't have." end if d[0].empty? && d[1].empty? @out.puts 'ok' end end |
#cleanup(args, options) ⇒ Object
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
# File 'lib/milkode/cdstk/cdstk.rb', line 531 def cleanup(args, ) update_display_info() if ([:all]) cleanup_all() elsif ([:packages]) cleanup_packages else print_result do db_open args.each do |arg| package = @yaml.find_name(arg) || @yaml.find_dir(arg) unless package path = File.(arg) package = @yaml.package_root(path) if File.exist?(path) end if (package) @documents.cleanup_package_name(package.name) # TODO: Support ignore_checker else @out.puts "Not found package '#{arg}'." return end end end end end |
#cleanup_all(options) ⇒ Object
580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/milkode/cdstk/cdstk.rb', line 580 def cleanup_all() if ([:force] or yes_or_no("cleanup contents? (yes/no)")) print_result do # Remove non exist packages cleanup_packages_in # @todo Remove ignore files @documents.cleanup do |record| alert("rm_record", record.path) @file_count += 1 end end end end |
#cleanup_packages ⇒ Object
Remove non exist pakcages
561 562 563 564 565 |
# File 'lib/milkode/cdstk/cdstk.rb', line 561 def cleanup_packages print_result do cleanup_packages_in end end |
#cleanup_packages_in ⇒ Object
567 568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/milkode/cdstk/cdstk.rb', line 567 def cleanup_packages_in @yaml.contents.find_all {|v| !File.exist? v.directory }.each do |p| @yaml.remove(p) alert("rm_package", p.directory) @package_count += 1 end @yaml.save db_open @grndb.yaml_sync(@yaml.contents) end |
#clear_count ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/milkode/cdstk/cdstk.rb', line 46 def clear_count @package_count = 0 @file_count = 0 @add_count = 0 @update_count = 0 @start_time = Time.now end |
#config(args, options) ⇒ Object
1040 1041 1042 1043 1044 1045 1046 |
# File 'lib/milkode/cdstk/cdstk.rb', line 1040 def config(args, ) if args.empty? config_print else config_set(args, ) end end |
#config_print ⇒ Object
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 |
# File 'lib/milkode/cdstk/cdstk.rb', line 1048 def config_print package = find_package_current_dir return if package.nil? @out.puts "Ignore:" package.ignore.each do |v| @out.puts " #{v}" end @out.puts "Options:" package..each do |key, value| @out.puts " #{(key.to_s + ':').ljust(CONFIG_LJUST)} #{value}" end end |
#config_set(args, options) ⇒ Object
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 |
# File 'lib/milkode/cdstk/cdstk.rb', line 1064 def config_set(args, ) package = find_package_current_dir return if package.nil? opt = package. if [:delete] opt.delete(args[0].to_sym) else if args.size == 2 opt[args[0].to_sym] = config_to_value(args[1]) else @out.puts("[usage] milk config KEY VALUE") end end package.(opt) @yaml.save end |
#config_to_value(v) ⇒ Object
config_to_value(‘true’) #=> true config_to_value(‘false’) #=> false config_to_value(‘abc’) #=> ‘abc’
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 |
# File 'lib/milkode/cdstk/cdstk.rb', line 1088 def config_to_value(v) case v when 'true' true when 'false' false else v end end |
#convert_content(src, options) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/milkode/cdstk/cdstk.rb', line 228 def convert_content(src, ) # httpファイルならダウンロード begin src = download_file(src, ) rescue AddError => e raise e rescue => e error_alert("download failure '#{src}'.") raise e # そのまま上に持ち上げてスタックトレース表示 end # アーカイブファイルなら展開 begin src = extract_file(src) rescue => e error_alert("extract failure '#{src}'.") raise e # そのまま上に持ち上げてスタックトレース表示 end # 絶対パスに変換 File.(src) end |
#dir(args, options) ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/milkode/cdstk/cdstk.rb', line 653 def dir(args, ) if args.empty? path = File.('.') package = @yaml.package_root(path) if (package) @out.print package.directory + ([:top] ? "" : "\n") else # Use mcd. @out.print "Not registered." + ([:top] ? "" : "\n") end else match_p = @yaml.contents.find_all do |p| args.all? {|k| p.name.include? k } end dirs = match_p.map{|v|v.directory}.reverse if [:top] unless (dirs.empty?) @out.print dirs[0] else @out.print "" end else @out.puts dirs end end end |
#download_file(src, options) ⇒ Object
264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/milkode/cdstk/cdstk.rb', line 264 def download_file(src, ) if git_protocol?(, src) git_clone_in(src, ) elsif svn_protocol?(, src) svn_clone_in(src, ) elsif src =~ /^https?:/ download_file_in(src) else raise AddError, "'--name' option is not available in local directory." if [:name] src end end |
#download_file_in(url) ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/milkode/cdstk/cdstk.rb', line 277 def download_file_in(url) alert("download", "#{url}") dst_dir = File.join(@db_dir, "packages/http") FileUtils.mkdir_p dst_dir filename = File.join(dst_dir, File.basename(url)) open(url) do |src| open(filename, "wb") do |dst| dst.write(src.read) end end filename end |
#dump ⇒ Object
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
# File 'lib/milkode/cdstk/cdstk.rb', line 635 def dump db_open @documents.each do |grnrcd| record = DocumentRecord.new grnrcd @out.puts record.inspect @out.puts "path : #{record.path}" @out.puts "shortpath : #{record.shortpath}" @out.puts "suffix : #{record.suffix}" @out.puts "timestamp : #{record..strftime('%Y/%m/%d %H:%M:%S')}" @out.puts "content :", record.content ? record.content[0..64] : nil @out.puts end @out.puts "total #{@documents.size} record." end |
#extract_file(src) ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/milkode/cdstk/cdstk.rb', line 251 def extract_file(src) ext = File.extname(src); case ext when '.zip', '.xpi' alert("extract", "#{src}") zip_dir = File.join(@db_dir, "packages/#{ext.sub(".", "")}") result = File.join(zip_dir, Util.zip_extract(src, zip_dir)) else src end end |
#fav(args, options) ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/milkode/cdstk/cdstk.rb', line 436 def fav(args, ) db_open if ([:sync_yaml]) is_dirty = false @yaml.contents.each do |package| db_fav = @grndb.packages.fav?(package.name) if package.fav? != db_fav @out.puts "#{package.name} : #{package.fav?} -> #{db_fav}" package.set_fav(db_fav) is_dirty = true end end @yaml.save if is_dirty elsif (args.empty?) @out.puts @grndb.packages.favs.map{|r| r.name} else is_dirty = false args.each do |v| # database time = [:delete] ? Time.at(0) : Time.now if @grndb.packages.touch_if(v, :favtime, time) # milkode_yaml package = @yaml.find_name(v) dst = package. unless [:delete] dst[:fav] = true else dst.delete(:fav) end package.(dst) @yaml.update(package) is_dirty = true else @out.puts "Not found package '#{v}'" end end @yaml.save if is_dirty end end |
#files(args, options) ⇒ Object
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/milkode/cdstk/cdstk.rb', line 1017 def files(args, ) packages = [:all] ? @yaml.contents : find_packages(args) return if (packages.empty?) db_open basedir = File.('.') if [:relative] packages.each do |package| package_records(package.name).each do |record| if [:relative] @out.puts Util.relative_path(record.path, basedir) else if [:all] @out.puts record.path else @out.puts record.restpath end end end end end |
#find_package_current_dir ⇒ Object
941 942 943 944 945 946 |
# File 'lib/milkode/cdstk/cdstk.rb', line 941 def find_package_current_dir dir = File.('.') package = @yaml.package_root(dir) @out.puts "Not registered '#{dir}'." if package.nil? package end |
#find_packages(args) ⇒ Object
引数が指定されている時は名前にマッチするパッケージを、未指定の時は現在位置から見つける
929 930 931 932 933 934 935 936 937 938 939 |
# File 'lib/milkode/cdstk/cdstk.rb', line 929 def find_packages(args) unless args.empty? args.map do |v| r = @yaml.find_name(v) @out.puts "Not found package '#{v}'." if r.nil? r end else [find_package_current_dir].compact end end |
#git_clone_in(url, options) ⇒ Object
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/milkode/cdstk/cdstk.rb', line 294 def git_clone_in(url, ) dst_dir = File.join(@db_dir, "packages/git") name = [:name] || File.basename(url).sub(/\.git\Z/, "") filename = File.join(dst_dir, name) unless File.exist?(filename) # git output progress to stderr. # `git clone #{url} #{filename} 2>&1` # with output if [:branch_name] alert("git", "#{url} (#{[:branch_name]})") system("git clone #{url} #{filename} -b #{[:branch_name]}") else alert("git", url) system("git clone #{url} #{filename}") end end filename end |
#ignore(args, options) ⇒ Object
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 |
# File 'lib/milkode/cdstk/cdstk.rb', line 948 def ignore(args, ) if [:global] if args.size > 0 @yaml.set_global_gitignore(args[0]) @yaml.save @out.puts "Set '#{args[0]}'" else if @yaml.global_gitignore @out.puts @yaml.global_gitignore end end return end current_dir = File.('.') if ([:package]) package = @yaml.find_name([:package]) raise IgnoreError, "Not found package '#{[:package]}'." unless package else package = @yaml.package_root(current_dir) raise IgnoreError, "Not a package dir: '#{current_dir}'" unless package end if [:dry_run] # Test mode db_open @is_display_info = true @is_silent = true update_dir_in(package.directory) elsif [:delete_all] # Delete all package.set_ignore([]) @yaml.update(package) @yaml.save elsif args.empty? # Display ignore settting @out.puts package.ignore else # Add or Delete if [:package] add_ignore = args.map {|v| v.sub(/^.\//, "") } else path = Util.relative_path(File.('.'), package.directory).to_s add_ignore = args.map {|v| File.join(path, v).sub(/^.\//, "") } end ignore = package.ignore if [:delete] ignore -= add_ignore else ignore += add_ignore end ignore.uniq! package.set_ignore(ignore) @yaml.update(package) @yaml.save if [:delete] @out.puts add_ignore.map{|v| "Delete : #{v}"} else @out.puts add_ignore.map{|v| "Add : #{v}"} end end end |
#info(args, options) ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/milkode/cdstk/cdstk.rb', line 741 def info(args, ) db_open if [:all] info_format(@yaml.contents, select_format(, :table)) milkode_info return end packages = find_packages(args) packages.compact! return if (packages.empty?) info_format(packages, select_format(, :detail)) end |
#info_format(packages, format) ⇒ Object
766 767 768 769 770 771 772 773 774 775 776 777 |
# File 'lib/milkode/cdstk/cdstk.rb', line 766 def info_format(packages, format) case format when :detail info_format_detail(packages) when :table info_format_table(packages) when :breakdown info_format_breakdown(packages) when :unknown info_format_unknown(packages) end end |
#info_format_breakdown(packages) ⇒ Object
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 |
# File 'lib/milkode/cdstk/cdstk.rb', line 815 def info_format_breakdown(packages) packages.each_with_index do |package, index| records = package_records(package.name) plangs = sorted_plangs(records) # column1's width plang_names = plangs.map{|v| v[0]} max = (plang_names + [package.name, TOTAL]).map{|name| name.length}.max @out.puts if index != 0 @out.puts <<EOF.chomp #{package.name.ljust(max)} files rate #{'=' * max}============= #{breakdown_detail(package_records(package.name), max)} #{'-' * max}------------- #{sprintf("%-#{max}s %5d %3d%%", TOTAL, records.size, 100)} EOF end end |
#info_format_detail(packages) ⇒ Object
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
# File 'lib/milkode/cdstk/cdstk.rb', line 779 def info_format_detail(packages) packages.each_with_index do |package, index| records = package_records(package.name) r = [] r.push "Name: #{package.name}" r.push "Ignore: #{package.ignore}" unless package.ignore.empty? r.push "Options: #{package.}" unless package..empty? r.push "Records: #{records.size}" r.push "Breakdown: #{breakdown_shorten(records)}" r.push "Linecount: #{linecount_total(records)}" r.push "" @out.puts if index != 0 @out.puts r.join("\n") end end |
#info_format_table(packages) ⇒ Object
800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/milkode/cdstk/cdstk.rb', line 800 def info_format_table(packages) max = packages.map{|p| p.name.length}.max max = NAME.length if max < NAME.length @out.puts <<EOF.chomp #{NAME.ljust(max)} Records Linecount #{'=' * max}======================== EOF packages.each do |package| records = package_records(package.name) @out.puts "#{package.name.ljust(max)} #{records.size.to_s.rjust(10)} #{linecount_total(records).to_s.rjust(10)}" end end |
#info_format_unknown(packages) ⇒ Object
835 836 837 838 839 840 841 842 843 844 |
# File 'lib/milkode/cdstk/cdstk.rb', line 835 def info_format_unknown(packages) packages.each_with_index do |package, index| @out.puts if index != 0 package_records(package.name).each do |record| path = record.restpath @out.puts path if PlangDetector.new(path).unknown? end end end |
#init(options) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/milkode/cdstk/cdstk.rb', line 54 def init() if Dir.emptydir?(@db_dir) @yaml = YamlFileWrapper.create(@db_dir) @out.puts "create : #{yaml_file}" db_create setdb([@db_dir], {}) if ([:setdb]) else @out.puts "Can't create milkode db (Because not empty in #{})" end end |
#linecount_total(records) ⇒ Object
850 851 852 853 854 855 856 857 858 859 860 861 862 863 |
# File 'lib/milkode/cdstk/cdstk.rb', line 850 def linecount_total(records) records.reduce(0) do |total, record| begin unless record.content.nil? total + record.content.count($/) + 1 else total end rescue ArgumentError warning_alert("invalid byte sequence : #{record.path}") total end end end |
#list(args, options) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/milkode/cdstk/cdstk.rb', line 400 def list(args, ) if [:check] check_integrity return end match_p = @yaml.contents.find_all do |p| args.all? {|k| p.name.include? k } end max = match_p.map{|p| p.name.length}.max str = match_p.sort_by {|p| p.name }.map {|p| h = File.exist?(p.directory) ? '' : '? ' if ([:verbose]) "#{(h + p.name).ljust(max+2)} #{p.directory}" elsif ([:directory]) "#{p.directory}" else "#{h}#{p.name}" end }.join("\n") @out.puts str if ![:directory] && Util.pipe?($stdout) if args.empty? milkode_info else list_info(match_p) unless match_p.empty? end end end |
#mcd(options) ⇒ Object
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/milkode/cdstk/cdstk.rb', line 701 def mcd() if [:shell] != 'cygwin' @out.print <<EOF # Copy to '.bashrc'. mcd() { local args="$1 $2 $3 $4 $5 $6 $7 $8 $9" local dir=`milk dir --top $args` if [ "$dir" = "" ]; then echo "fatal: Not found package: $1 $2 $3 $4 $5 $6 $7 $8 $9" elif [ "$dir" = "Not registered." ]; then echo "fatal: Not a package dir: `pwd`" else cd $dir pwd fi } EOF end if [:shell] != 'sh' @out.print <<EOF # For Cygwin. mcd() { local args="$1 $2 $3 $4 $5 $6 $7 $8 $9" local dir=`milk.bat dir --top $args` if [ "$dir" = "" ]; then echo "fatal: Not found package: $1 $2 $3 $4 $5 $6 $7 $8 $9" elif [ "$dir" = "Not registered." ]; then echo "fatal: Not a package dir: `pwd`" else cd $dir pwd fi } EOF end end |
#package_records(name) ⇒ Object
846 847 848 |
# File 'lib/milkode/cdstk/cdstk.rb', line 846 def package_records(name) @documents.search(:strict_packages => [name]) end |
#pwd(options) ⇒ Object
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
# File 'lib/milkode/cdstk/cdstk.rb', line 506 def pwd() dir = [:default] ? Dbdir.default_dir : if File.exist? dir if [:default] @out.puts dir else package = @yaml.package_root(File.('.')) name = "" if package name = package.name elsif Dbdir.dbdir? name = 'On database' else name = 'Not package dir' end @out.puts "#{name} in #{dir}" end else @out.puts "Not found db in #{Dir.pwd}" end end |
#rebuild(args, options) ⇒ Object
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/milkode/cdstk/cdstk.rb', line 595 def rebuild(args, ) update_display_info() if ([:all]) db_delete db_create @grndb.yaml_sync(@yaml.contents) update_all({}) else if (args.empty?) path = File.('.') package = @yaml.package_root(path) if (package) print_result do db_open remove_dir(package.directory, true) add_dir(package.directory, true) end else @out.puts "Not registered. '#{path}'." end else print_result do args.each do |name| package = @yaml.find_name(name) if (package) db_open remove_dir(package.directory, true) add_dir(package.directory, true) else @out.puts "Not found package '#{name}'." return end end end end end end |
#remove(args, options) ⇒ Object
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/milkode/cdstk/cdstk.rb', line 355 def remove(args, ) update_display_info() if ([:all]) remove_all else print_result do db_open args.each do |arg| package = @yaml.find_name(arg) || @yaml.find_dir(arg) unless package path = File.(arg) package = @yaml.package_root(path) if File.exist?(path) end if (package) remove_dir(package.directory) else @out.puts "Not found package '#{arg}'." return end end end end end |
#remove_all ⇒ Object
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/milkode/cdstk/cdstk.rb', line 329 def remove_all print_result do list([], {:verbose => true}) if yes_or_no("Remove #{@yaml.contents.size} contents? (yes/no)") db_open # documents @documents.remove_all do |record| alert_info("rm_record", record.path) @file_count += 1 end # packages @grndb.packages.remove_all # yaml @package_count += @yaml.contents.size @yaml.remove_all @yaml.save else return end end end |
#select_format(options, default_value) ⇒ Object
757 758 759 760 761 762 763 764 |
# File 'lib/milkode/cdstk/cdstk.rb', line 757 def select_format(, default_value) format = default_value format = :detail if [:detail] format = :table if [:table] format = :breakdown if [:breakdown] format = :unknown if [:unknown] format end |
#set_yaml_options(package, options, is_update_with_git_pull, is_update_with_svn_update) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/milkode/cdstk/cdstk.rb', line 164 def (package, , is_update_with_git_pull, is_update_with_svn_update) is_dirty = false if [:no_auto_ignore] dst = package. dst[:no_auto_ignore] = true package.(dst) is_dirty = true end # ローカルディレクトリの名前変更は後回し # if options[:name] # dst = package.options # dst[:name] = src[:name] # package.set_options(dst) # is_dirty = true # end if is_update_with_git_pull dst = package. dst[:update_with_git_pull] = is_update_with_git_pull package.(dst) is_dirty = true end if is_update_with_svn_update dst = package. dst[:update_with_svn_update] = is_update_with_svn_update package.(dst) is_dirty = true end if is_dirty @yaml.update(package) @yaml.save end end |
#setdb(args, options) ⇒ Object
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/milkode/cdstk/cdstk.rb', line 683 def setdb(args, ) if ([:reset]) CdstkCommand.setdb_reset @out.puts "Reset default db\n remove: #{Dbdir.milkode_db_dir}\n default_db: #{Dbdir.default_dir}" elsif (args.empty?) @out.puts Dbdir.default_dir else dbpath = args.first path = File.(dbpath) begin CdstkCommand.setdb_set path @out.puts "Set default db #{path}." rescue CdstkCommand::NotExistDatabase @out.puts "fatal: '#{path}' is not database." end end end |
#sorted_plangs(records) ⇒ Object
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 |
# File 'lib/milkode/cdstk/cdstk.rb', line 865 def sorted_plangs(records) total = {} records.each do |record| lang = PlangDetector.new(record.restpath) if total[lang.name] total[lang.name] += 1 else total[lang.name] = 1 end end total.map {|name, count| [name, count] }.sort {|a, b| if (a[0] == PlangDetector::UNKNOWN) -1 elsif (b[0] == PlangDetector::UNKNOWN) 1 else a[1] <=> b[1] end }.reverse end |
#svn_clone_in(url, options) ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'lib/milkode/cdstk/cdstk.rb', line 316 def svn_clone_in(url, ) alert("svn", url) dst_dir = File.join(@db_dir, "packages/svn") name = [:name] || File.basename(url) filename = File.join(dst_dir, name) # with output system("svn checkout #{url} #{filename}") filename end |
#update(args, options) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/milkode/cdstk/cdstk.rb', line 79 def update(args, ) update_display_info() if ([:all]) update_all() else if (args.empty?) path = File.('.') package = @yaml.package_root(path) if (package) print_result do db_open update_package_in(package, ) end else @out.puts "Not registered. If you want to add, 'milk add #{path}'." end else print_result do db_open args.each do |name| package = @yaml.find_name(name) if (package) update_package_in(package, ) else @out.puts "Not found package '#{name}'." return end end end end end end |
#update_all(options) ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/milkode/cdstk/cdstk.rb', line 69 def update_all() print_result do db_open @yaml.contents.each do |package| update_package_in(package, ) end end end |
#update_for_grep(dir) ⇒ Object
114 115 116 117 |
# File 'lib/milkode/cdstk/cdstk.rb', line 114 def update_for_grep(dir) db_open update_dir_in(dir) end |
#yes_or_no(msg) ⇒ Object
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/milkode/cdstk/cdstk.rb', line 382 def yes_or_no(msg) if ($no_readline) @out.puts "Pass Cdstk#yes_or_no, because fail \"require 'readline'\"." return true end @out.puts msg while buf = Readline.readline("> ") case buf when 'yes' return true when 'no' break end end return false end |