def main(): Args.valid_anywhere = ["help"] Args.valid_options = ["version", "verbose", "strict"] Args.valid_commands = [] Args.valid_keys = [] #Args.command_aliases = {"?":"help", "ls":"list"} Args.process()
def main(): Args.valid_anywhere= ["help"] Args.valid_options = ["version", "verbose", "strict"] Args.valid_commands = [] Args.valid_keys = [] #Args.command_aliases = {"?":"help", "ls":"list"} Args.process()
def compatible(project): support = Support.ENVIRONMENT | Support.PROJECT # no auto if Args.option("clean"): support |= Support.USER return support
def update(project): try: project.generate except: project.generate = [] if "premake" in project.generate: generate(project) # can throw try: project.makepath = os.path.abspath(os.path.expanduser(Settings.get('make_path'))) except: project.makepath = "" # make sure theres a make step after premake make_step = Plugin("steps", "make", "makefile") conf_step = Plugin("steps", "make", "configure") if os.name == "nt": msb_step = Plugin("steps", "make", "msbuild") project.clean_commands = ["%s clean" % os.path.join(project.makepath,"make")] try: project.makefile_params except: project.makefile_params = [] if Args.option("debug"): project.makefile_params += ["config=debug"] else: project.makefile_params += ["config=release"] clean_step = Plugin("steps", "clean", "clean") if make_step in project.steps: project.steps.remove(make_step) if conf_step in project.steps: project.steps.remove(conf_step) if os.name == "nt": if msb_step in project.steps: project.steps.remove(msb_step) if clean_step in project.steps: project.steps.remove(clean_step) i = 0 if os.name == "nt": make_step = msb_step for s in project.steps: if s.type == "make" and s.name == "premake": # TODO: check for user support (because of -r flag) if clean.clean.compatible(project) & Support.USER: project.steps.insert(i, clean_step) project.steps.insert(i+2, make_step) else: project.steps.insert(i+1, make_step) break i += 1 make_step.call("update", project)
def main(): # interactive lets you check each flag for the plug-in while projects are being built Args.valid_options = ["?", "help", "interactive", "warn", "verbose", "edit", "overwrite", "remove", "list"] Args.valid_keys = ["separator-char", "switch-char", "type-default", "switch-default", "title"] # --ignore=context Args.process() set_program_name(Args.value("title")) if Args.option("help") or Args.option("?"): help() return # check for bad options (not yet implemented) for bad in ("interactive", "warn", "remove", "edit"): if Args.option(bad): error("option '%s' not yet implemented" % bad) return # loop through provided filenames if Args.filenames: for fn in Args.filenames: try: t = Project(fn) except Exception as e: error(e) #except Exception as e: # return # if t: else: error("missing file operand" % program_name()) return
def make(project): try: project.makepath = os.path.abspath(os.path.expanduser(Settings.get('make_path'))) except: project.makepath = "" # TODO: detect a suitable vcvars if the environment isn't init cmdline = [os.path.join(project.makepath,"msbuild")] cmdline += ["/p:Platform=Win32"] if Args.option("debug"): cmdline += ["/p:Configuration=Debug"] else: cmdline += ["/p:Configuration=Release"] if project.msbuild_params: cmdline += project.msbuild_params try: os.chdir(project.build_dir) except: pass try: call(cmdline) except subprocess.CalledProcessError: try: if project.build_dir: os.chdir("..") except: pass return Status.FAILURE try: if project.build_dir: os.chdir("..") except: pass return Status.SUCCESS
def try_project(fn): """ Calls necessary detection methods on a potential project path Parameter is an os.path """ # save previous dir so we can pop back into it wdir = os.getcwd() if fn.startswith( ".") and fn != "." and fn != "..": # check if path is hidden return 0 if not os.path.isdir(os.path.join(fn)): return 0 if os.path.islink(fn): return 0 # push new dir os.chdir(fn) project = detect_project() listed = False if project and not project.status == Status.UNSUPPORTED: print "%s (%s)" % (project.name, os.path.relpath(os.getcwd(), wdir)) listed = True if Args.anywhere("list"): os.chdir(wdir) return 1 if listed else 0 if listed: if project.complete(): os.chdir(wdir) return 1 else: os.chdir(wdir) return -1 os.chdir(wdir) return 0
def try_project(fn): """ Calls necessary detection methods on a potential project path Parameter is an os.path """ # save previous dir so we can pop back into it wdir = os.getcwd() if fn.startswith(".") and fn != "." and fn != "..": # check if path is hidden return 0 if not os.path.isdir(os.path.join(fn)): return 0 if os.path.islink(fn): return 0 # push new dir os.chdir(fn) project = detect_project() listed = False if project and not project.status == Status.UNSUPPORTED: print "%s (%s)" % (project.name, os.path.relpath(os.getcwd(), wdir)) listed = True if Args.anywhere("list"): os.chdir(wdir) return 1 if listed else 0 if listed: if project.complete(): os.chdir(wdir) return 1 else: os.chdir(wdir) return -1 os.chdir(wdir) return 0
def main(): # interactive lets you check each flag for the plug-in while projects are being built Args.valid_options = [ "?", "help", "interactive", "warn", "verbose", "edit", "overwrite", "remove", "list" ] Args.valid_keys = [ "separator-char", "switch-char", "type-default", "switch-default", "title" ] # --ignore=context Args.process() set_program_name(Args.value("title")) if Args.option("help") or Args.option("?"): help() return # check for bad options (not yet implemented) for bad in ("interactive", "warn", "remove", "edit"): if Args.option(bad): error("option '%s' not yet implemented" % bad) return # loop through provided filenames if Args.filenames: for fn in Args.filenames: try: t = Project(fn) except Exception as e: error(e) #except Exception as e: # return # if t: else: error("missing file operand" % program_name()) return
def __init__(self): # Parse the args args = self._parse_args() # Create/load config config = None self.config_path = os.path.join(args.config_dir, Seedsync.__FILE_CONFIG) create_default_config = False if os.path.isfile(self.config_path): try: config = Config.from_file(self.config_path) except (ConfigError, PersistError): Seedsync.__backup_file(self.config_path) # set config to default create_default_config = True else: create_default_config = True if create_default_config: # Create default config config = Seedsync._create_default_config() config.to_file(self.config_path) # Determine the true value of debug is_debug = args.debug or config.general.debug # Create context args ctx_args = Args() ctx_args.local_path_to_scanfs = args.scanfs ctx_args.html_path = args.html ctx_args.debug = is_debug ctx_args.exit = args.exit # Logger setup # We separate the main log from the web-access log logger = self._create_logger(name=Constants.SERVICE_NAME, debug=is_debug, logdir=args.logdir) Seedsync.logger = logger web_access_logger = self._create_logger( name=Constants.WEB_ACCESS_LOG_NAME, debug=is_debug, logdir=args.logdir) logger.info( "Debug mode is {}.".format("enabled" if is_debug else "disabled")) # Create status status = Status() # Create context self.context = Context(logger=logger, web_access_logger=web_access_logger, config=config, args=ctx_args, status=status) # Register the signal handlers signal.signal(signal.SIGTERM, self.signal) signal.signal(signal.SIGINT, self.signal) # Print context to log self.context.print_to_log() # Load the persists self.controller_persist_path = os.path.join( args.config_dir, Seedsync.__FILE_CONTROLLER_PERSIST) self.controller_persist = self._load_persist( ControllerPersist, self.controller_persist_path) self.auto_queue_persist_path = os.path.join( args.config_dir, Seedsync.__FILE_AUTO_QUEUE_PERSIST) self.auto_queue_persist = self._load_persist( AutoQueuePersist, self.auto_queue_persist_path)
def _process(self): verbose = Args.option("verbose") self.template.process() # may raise error
def main(): Args.valid_options = ["clean", "list", "debug", "version", "verbose", "strict", "warn", "recursive", "reversive", "execute", "x"] #, "interactive", "cache" Args.valid_keys = ["ignore"] Args.process() # process the build step plugins try: steps.ignore(Args.value("ignore").split(",")) # disable requested steps except AttributeError: pass steps.process() events.process() if Args.option("version"): splash() return 0 if Args.option("help") or Args.option("?"): help() return 0 # count of projects succeeded and failed success_count = 0 failed_count = 0 # if no project filenames are specified, we'll use the current directory (".") if not Args.filenames: Args.filenames = ["."] # check for forward recusion and backward scan settings recursive = Args.option("recursive") reversive = True #reversive = Args.option("reversive") execute = Args.option("x") or Args.option("execute") event("status", "start") if recursive: # TODO this recursion sucks, fix it later # recurse through directories until you find project(s) for fn in Args.filenames: if fn.startswith(".") and fn != "." and fn != "..": continue r = 0 for root, dirs, files in os.walk(fn): stop_recurse = False for d in dirs: base = os.path.basename(os.path.join(root,d)) if base.startswith(".") and base != ".": continue #print os.path.normpath(os.path.join(root,d)) r = try_project(os.path.normpath(os.path.join(root, d))) if r == 1: if not Args.option("list"): success_count += 1 stop_recurse = True elif r == -1: if not Args.option("list"): failed_count += 1 if stop_recurse: dirs[:] = [] elif reversive: # TODO search for project by iterating dirs backwards # To be used build a sgmake project from within a nested directory or source editor for fn in Args.filenames: path = os.path.abspath(os.path.join(os.getcwd(), fn)) while os.path.realpath(path) != os.path.expanduser('~'): #while os.path.realpath(path) != os.path.realpath(os.path.join(path, "..")): # is root r = try_project(os.path.normpath(path)) if r == 1: if not Args.option("list"): success_count += 1 break elif r == -1: if not Args.option("list"): failed_count += 1 break path = os.path.realpath(os.path.join(path, "..")) #print "done: %s" % path #else: # # try to build projects specified by the user, current dir is default # for fn in Args.filenames: # r = try_project(os.path.join(os.getcwd(),fn)) # if r == 1: # success_count += 1 # elif r == -1: # failed_count += 1 if not Args.command("list"): # if not in list-only mode, display final status of built projects if success_count: print("%s project(s) completed." % success_count) if not failed_count: event("status", "success") return 0 else: return 1 if failed_count: print("%s project(s) failed." % failed_count) event("status", "failure") return 1 elif not success_count and not failed_count: event("status", "nothing") print("Nothing to be done.") return 1 return 0
def __init__(self, fn): self.fn = fn self.filetype = None self.template = None if not self.fn: raise IOError() #Args = Args # get defaults or custom (user-provided) separator and switch chars sep_list = [Args.value("separator-char")] if Args.value("separator-char") else ['@', ':', ';'] switch_list = [Args.value("switch-char")] if Args.value("switch-char") else ['+'] # filename/type separators tokens = None # scope for sep in sep_list: tokens = self.fn.split(sep) token_count = len(tokens) if token_count == 2: self.fn = tokens[0] self.filetype = tokens[1] break tokens = None if not tokens: tokens = [self.fn] # get extension (even if unused) self.ext = None tokens = self.fn.split('.') if len(tokens) > 1: self.fn = tokens[0] # new filename (without ext) self.ext = '.'.join(tokens[1:]) # use everything past first dot, ex: tar.gz if not self.filetype: self.filetype = self.ext # get switches for typed projects (when type is explicitly stated) # FIXME if necessary: # this only allows switches to be used on projects where a type is specified (not infered from extension) # this may require a better parser if fixed self.switches = None if self.filetype: for switch in switch_list: tokens = self.filetype.split(switch) if len(tokens) > 1: self.filetype = tokens[0] #self.switches = tokens[1:] break # correct switch char found # check if filename and template exist (if so, "touch" (update date of) the file) self._locate() if Args.option("verbose") or Args.option("list"): print "Filename: %s%s" % (self.fn, " (already exists)" if self.exists else "") if self.filetype: print "- Template: %s" % self.filetype if self.switches: print "- Switches: %s" % ','.join(self.switches) if self.ext: print "- Extension: %s" % self.ext if self.exists: print "- Exists: %s" % self.exists if not Args.option("list"): r = self._process() # may raise error
def __init__(self, fn): self.fn = fn self.filetype = None self.template = None if not self.fn: raise IOError() #Args = Args # get defaults or custom (user-provided) separator and switch chars sep_list = [Args.value("separator-char") ] if Args.value("separator-char") else ['@', ':', ';'] switch_list = [Args.value("switch-char") ] if Args.value("switch-char") else ['+'] # filename/type separators tokens = None # scope for sep in sep_list: tokens = self.fn.split(sep) token_count = len(tokens) if token_count == 2: self.fn = tokens[0] self.filetype = tokens[1] break tokens = None if not tokens: tokens = [self.fn] # get extension (even if unused) self.ext = None tokens = self.fn.split('.') if len(tokens) > 1: self.fn = tokens[0] # new filename (without ext) self.ext = '.'.join( tokens[1:]) # use everything past first dot, ex: tar.gz if not self.filetype: self.filetype = self.ext # get switches for typed projects (when type is explicitly stated) # FIXME if necessary: # this only allows switches to be used on projects where a type is specified (not infered from extension) # this may require a better parser if fixed self.switches = None if self.filetype: for switch in switch_list: tokens = self.filetype.split(switch) if len(tokens) > 1: self.filetype = tokens[0] #self.switches = tokens[1:] break # correct switch char found # check if filename and template exist (if so, "touch" (update date of) the file) self._locate() if Args.option("verbose") or Args.option("list"): print "Filename: %s%s" % (self.fn, " (already exists)" if self.exists else "") if self.filetype: print "- Template: %s" % self.filetype if self.switches: print "- Switches: %s" % ','.join(self.switches) if self.ext: print "- Extension: %s" % self.ext if self.exists: print "- Exists: %s" % self.exists if not Args.option("list"): r = self._process() # may raise error
def main(): Args.valid_options = [ "clean", "list", "debug", "version", "verbose", "strict", "warn", "recursive", "reversive", "execute", "x" ] #, "interactive", "cache" Args.valid_keys = ["ignore"] Args.process() # process the build step plugins try: steps.ignore( Args.value("ignore").split(",")) # disable requested steps except AttributeError: pass steps.process() events.process() if Args.option("version"): splash() return 0 if Args.option("help") or Args.option("?"): help() return 0 # count of projects succeeded and failed success_count = 0 failed_count = 0 # if no project filenames are specified, we'll use the current directory (".") if not Args.filenames: Args.filenames = ["."] # check for forward recusion and backward scan settings recursive = Args.option("recursive") reversive = True #reversive = Args.option("reversive") execute = Args.option("x") or Args.option("execute") event("status", "start") if recursive: # TODO this recursion sucks, fix it later # recurse through directories until you find project(s) for fn in Args.filenames: if fn.startswith(".") and fn != "." and fn != "..": continue r = 0 for root, dirs, files in os.walk(fn): stop_recurse = False for d in dirs: base = os.path.basename(os.path.join(root, d)) if base.startswith(".") and base != ".": continue #print os.path.normpath(os.path.join(root,d)) r = try_project(os.path.normpath(os.path.join(root, d))) if r == 1: if not Args.option("list"): success_count += 1 stop_recurse = True elif r == -1: if not Args.option("list"): failed_count += 1 if stop_recurse: dirs[:] = [] elif reversive: # TODO search for project by iterating dirs backwards # To be used build a sgmake project from within a nested directory or source editor for fn in Args.filenames: path = os.path.abspath(os.path.join(os.getcwd(), fn)) while os.path.realpath(path) != os.path.expanduser('~'): #while os.path.realpath(path) != os.path.realpath(os.path.join(path, "..")): # is root r = try_project(os.path.normpath(path)) if r == 1: if not Args.option("list"): success_count += 1 break elif r == -1: if not Args.option("list"): failed_count += 1 break path = os.path.realpath(os.path.join(path, "..")) #print "done: %s" % path #else: # # try to build projects specified by the user, current dir is default # for fn in Args.filenames: # r = try_project(os.path.join(os.getcwd(),fn)) # if r == 1: # success_count += 1 # elif r == -1: # failed_count += 1 if not Args.command("list"): # if not in list-only mode, display final status of built projects if success_count: print("%s project(s) completed." % success_count) if not failed_count: event("status", "success") return 0 else: return 1 if failed_count: print("%s project(s) failed." % failed_count) event("status", "failure") return 1 elif not success_count and not failed_count: event("status", "nothing") print("Nothing to be done.") return 1 return 0
def update(project): try: project.generate except: project.generate = [] if "premake" in project.generate: generate(project) # can throw try: project.makepath = os.path.abspath( os.path.expanduser(Settings.get('make_path'))) except: project.makepath = "" # make sure theres a make step after premake make_step = Plugin("steps", "make", "makefile") conf_step = Plugin("steps", "make", "configure") if os.name == "nt": msb_step = Plugin("steps", "make", "msbuild") project.clean_commands = [ "%s clean" % os.path.join(project.makepath, "make") ] try: project.makefile_params except: project.makefile_params = [] if Args.option("debug"): project.makefile_params += ["config=debug"] else: project.makefile_params += ["config=release"] clean_step = Plugin("steps", "clean", "clean") if make_step in project.steps: project.steps.remove(make_step) if conf_step in project.steps: project.steps.remove(conf_step) if os.name == "nt": if msb_step in project.steps: project.steps.remove(msb_step) if clean_step in project.steps: project.steps.remove(clean_step) i = 0 if os.name == "nt": make_step = msb_step for s in project.steps: if s.type == "make" and s.name == "premake": # TODO: check for user support (because of -r flag) if clean.clean.compatible(project) & Support.USER: project.steps.insert(i, clean_step) project.steps.insert(i + 2, make_step) else: project.steps.insert(i + 1, make_step) break i += 1 make_step.call("update", project)