Lines Matching refs:self
136 def __init__(self, attrs=None):
148 self.verbose = 1
149 self.dry_run = 0
150 self.help = 0
151 for attr in self.display_option_names:
152 setattr(self, attr, 0)
159 self.metadata = DistributionMetadata()
160 for basename in self.metadata._METHOD_BASENAMES:
162 setattr(self, method_name, getattr(self.metadata, method_name))
168 self.cmdclass = {}
176 self.command_packages = None
181 self.script_name = None
182 self.script_args = None
189 self.command_options = {}
200 self.dist_files = []
205 self.packages = None
206 self.package_data = {}
207 self.package_dir = None
208 self.py_modules = None
209 self.libraries = None
210 self.headers = None
211 self.ext_modules = None
212 self.ext_package = None
213 self.include_dirs = None
214 self.extra_path = None
215 self.scripts = None
216 self.data_files = None
217 self.password = ''
223 self.command_obj = {}
235 self.have_run = {}
250 opt_dict = self.get_option_dict(command)
266 if hasattr(self.metadata, "set_" + key):
267 getattr(self.metadata, "set_" + key)(val)
268 elif hasattr(self.metadata, key):
269 setattr(self.metadata, key, val)
270 elif hasattr(self, key):
271 setattr(self, key, val)
282 self.want_user_cfg = True
284 if self.script_args is not None:
285 for arg in self.script_args:
289 self.want_user_cfg = False
292 self.finalize_options()
294 def get_option_dict(self, command):
300 dict = self.command_options.get(command)
302 dict = self.command_options[command] = {}
305 def dump_option_dicts(self, header=None, commands=None, indent=""):
309 commands = sorted(self.command_options.keys())
312 self.announce(indent + header)
316 self.announce(indent + "no commands known yet")
320 opt_dict = self.command_options.get(cmd_name)
322 self.announce(indent +
325 self.announce(indent +
329 self.announce(indent + " " + line)
333 def find_config_files(self):
366 if self.want_user_cfg:
377 self.announce("using config files: %s" % ', '.join(files))
381 def parse_config_files(self, filenames=None):
397 filenames = self.find_config_files()
400 self.announce("Distribution.parse_config_files():")
405 self.announce(" reading %s" % filename)
409 opt_dict = self.get_option_dict(section)
424 if 'global' in self.command_options:
425 for (opt, (src, val)) in self.command_options['global'].items():
426 alias = self.negative_opt.get(opt)
429 setattr(self, alias, not strtobool(val))
431 setattr(self, opt, strtobool(val))
433 setattr(self, opt, val)
439 def parse_command_line(self):
462 toplevel_options = self._get_toplevel_options()
471 self.commands = []
472 parser = FancyGetopt(toplevel_options + self.display_options)
473 parser.set_negative_aliases(self.negative_opt)
475 args = parser.getopt(args=self.script_args, object=self)
477 log.set_verbosity(self.verbose)
480 if self.handle_display_options(option_order):
483 args = self._parse_command_opts(parser, args)
493 if self.help:
494 self._show_help(parser,
495 display_options=len(self.commands) == 0,
496 commands=self.commands)
500 if not self.commands:
506 def _get_toplevel_options(self):
512 return self.global_options + [
517 def _parse_command_opts(self, parser, args):
533 self.commands.append(command)
539 cmd_class = self.get_command_class(command)
559 negative_opt = self.negative_opt
574 parser.set_option_table(self.global_options +
580 self._show_help(parser, display_options=0, commands=[cmd_class])
602 opt_dict = self.get_option_dict(command)
608 def finalize_options(self):
614 value = getattr(self.metadata, attr)
619 setattr(self.metadata, attr, value)
621 def _show_help(self, parser, global_options=1, display_options=1,
641 options = self._get_toplevel_options()
643 options = self.global_options
645 parser.print_help(self.common_usage + "\nGlobal options:")
649 parser.set_option_table(self.display_options)
655 for command in self.commands:
659 klass = self.get_command_class(command)
669 print(gen_usage(self.script_name))
671 def handle_display_options(self, option_order):
682 if self.help_commands:
683 self.print_commands()
685 print(gen_usage(self.script_name))
693 for option in self.display_options:
699 value = getattr(self.metadata, "get_"+opt)()
711 def print_command_list(self, commands, header, max_length):
718 klass = self.cmdclass.get(cmd)
720 klass = self.get_command_class(cmd)
728 def print_commands(self):
732 (mentioned in self.cmdclass, but not a standard command). The
743 for cmd in self.cmdclass.keys():
752 self.print_command_list(std_commands,
757 self.print_command_list(extra_commands,
761 def get_command_list(self):
765 self.cmdclass, but not a standard command). The descriptions come
777 for cmd in self.cmdclass.keys():
783 klass = self.cmdclass.get(cmd)
785 klass = self.get_command_class(cmd)
795 def get_command_packages(self):
797 pkgs = self.command_packages
804 self.command_packages = pkgs
807 def get_command_class(self, command):
819 klass = self.cmdclass.get(command)
823 for pkgname in self.get_command_packages():
840 self.cmdclass[command] = klass
845 def get_command_obj(self, command, create=1):
851 cmd_obj = self.command_obj.get(command)
854 self.announce("Distribution.get_command_obj(): "
857 klass = self.get_command_class(command)
858 cmd_obj = self.command_obj[command] = klass(self)
859 self.have_run[command] = 0
866 options = self.command_options.get(command)
868 self._set_command_options(cmd_obj, options)
872 def _set_command_options(self, command_obj, option_dict=None):
879 (from 'self.command_options').
883 option_dict = self.get_option_dict(command_name)
886 self.announce(" setting options for '%s' command:" % command_name)
889 self.announce(" %s = %s (from %s)" % (option, value,
916 def reinitialize_command(self, command, reinit_subcommands=0):
938 command = self.get_command_obj(command_name)
946 self.have_run[command_name] = 0
947 self._set_command_options(command)
951 self.reinitialize_command(sub, reinit_subcommands)
957 def announce(self, msg, level=log.INFO):
960 def run_commands(self):
965 for cmd in self.commands:
966 self.run_command(cmd)
970 def run_command(self, command):
979 if self.have_run.get(command):
983 cmd_obj = self.get_command_obj(command)
986 self.have_run[command] = 1
990 def has_pure_modules(self):
991 return len(self.packages or self.py_modules or []) > 0
993 def has_ext_modules(self):
994 return self.ext_modules and len(self.ext_modules) > 0
996 def has_c_libraries(self):
997 return self.libraries and len(self.libraries) > 0
999 def has_modules(self):
1000 return self.has_pure_modules() or self.has_ext_modules()
1002 def has_headers(self):
1003 return self.headers and len(self.headers) > 0
1005 def has_scripts(self):
1006 return self.scripts and len(self.scripts) > 0
1008 def has_data_files(self):
1009 return self.data_files and len(self.data_files) > 0
1011 def is_pure(self):
1012 return (self.has_pure_modules() and
1013 not self.has_ext_modules() and
1014 not self.has_c_libraries())
1019 # they are defined in a sneaky way: the constructor binds self.get_XXX
1020 # to self.metadata.get_XXX. The actual code is in the
1037 def __init__(self, path=None):
1039 self.read_pkg_file(open(path))
1041 self.name = None
1042 self.version = None
1043 self.author = None
1044 self.author_email = None
1045 self.maintainer = None
1046 self.maintainer_email = None
1047 self.url = None
1048 self.license = None
1049 self.description = None
1050 self.long_description = None
1051 self.keywords = None
1052 self.platforms = None
1053 self.classifiers = None
1054 self.download_url = None
1056 self.provides = None
1057 self.requires = None
1058 self.obsoletes = None
1060 def read_pkg_file(self, file):
1077 self.name = _read_field('name')
1078 self.version = _read_field('version')
1079 self.description = _read_field('summary')
1081 self.author = _read_field('author')
1082 self.maintainer = None
1083 self.author_email = _read_field('author-email')
1084 self.maintainer_email = None
1085 self.url = _read_field('home-page')
1086 self.license = _read_field('license')
1089 self.download_url = _read_field('download-url')
1091 self.download_url = None
1093 self.long_description = _read_field('description')
1094 self.description = _read_field('summary')
1097 self.keywords = _read_field('keywords').split(',')
1099 self.platforms = _read_list('platform')
1100 self.classifiers = _read_list('classifier')
1104 self.requires = _read_list('requires')
1105 self.provides = _read_list('provides')
1106 self.obsoletes = _read_list('obsoletes')
1108 self.requires = None
1109 self.provides = None
1110 self.obsoletes = None
1112 def write_pkg_info(self, base_dir):
1117 self.write_pkg_file(pkg_info)
1119 def write_pkg_file(self, file):
1123 if (self.provides or self.requires or self.obsoletes or
1124 self.classifiers or self.download_url):
1128 file.write('Name: %s\n' % self.get_name())
1129 file.write('Version: %s\n' % self.get_version())
1130 file.write('Summary: %s\n' % self.get_description())
1131 file.write('Home-page: %s\n' % self.get_url())
1132 file.write('Author: %s\n' % self.get_contact())
1133 file.write('Author-email: %s\n' % self.get_contact_email())
1134 file.write('License: %s\n' % self.get_license())
1135 if self.download_url:
1136 file.write('Download-URL: %s\n' % self.download_url)
1138 long_desc = rfc822_escape(self.get_long_description())
1141 keywords = ','.join(self.get_keywords())
1145 self._write_list(file, 'Platform', self.get_platforms())
1146 self._write_list(file, 'Classifier', self.get_classifiers())
1149 self._write_list(file, 'Requires', self.get_requires())
1150 self._write_list(file, 'Provides', self.get_provides())
1151 self._write_list(file, 'Obsoletes', self.get_obsoletes())
1153 def _write_list(self, file, name, values):
1159 def get_name(self):
1160 return self.name or "UNKNOWN"
1162 def get_version(self):
1163 return self.version or "0.0.0"
1165 def get_fullname(self):
1166 return "%s-%s" % (self.get_name(), self.get_version())
1168 def get_author(self):
1169 return self.author or "UNKNOWN"
1171 def get_author_email(self):
1172 return self.author_email or "UNKNOWN"
1174 def get_maintainer(self):
1175 return self.maintainer or "UNKNOWN"
1177 def get_maintainer_email(self):
1178 return self.maintainer_email or "UNKNOWN"
1180 def get_contact(self):
1181 return self.maintainer or self.author or "UNKNOWN"
1183 def get_contact_email(self):
1184 return self.maintainer_email or self.author_email or "UNKNOWN"
1186 def get_url(self):
1187 return self.url or "UNKNOWN"
1189 def get_license(self):
1190 return self.license or "UNKNOWN"
1193 def get_description(self):
1194 return self.description or "UNKNOWN"
1196 def get_long_description(self):
1197 return self.long_description or "UNKNOWN"
1199 def get_keywords(self):
1200 return self.keywords or []
1202 def set_keywords(self, value):
1203 self.keywords = _ensure_list(value, 'keywords')
1205 def get_platforms(self):
1206 return self.platforms or ["UNKNOWN"]
1208 def set_platforms(self, value):
1209 self.platforms = _ensure_list(value, 'platforms')
1211 def get_classifiers(self):
1212 return self.classifiers or []
1214 def set_classifiers(self, value):
1215 self.classifiers = _ensure_list(value, 'classifiers')
1217 def get_download_url(self):
1218 return self.download_url or "UNKNOWN"
1221 def get_requires(self):
1222 return self.requires or []
1224 def set_requires(self, value):
1228 self.requires = list(value)
1230 def get_provides(self):
1231 return self.provides or []
1233 def set_provides(self, value):
1238 self.provides = value
1240 def get_obsoletes(self):
1241 return self.obsoletes or []
1243 def set_obsoletes(self, value):
1247 self.obsoletes = list(value)