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 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 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