Skip to content

Commit

Permalink
Added support for %config(noreplace) file flag
Browse files Browse the repository at this point in the history
  • Loading branch information
genereese committed Mar 19, 2018
1 parent 67585a0 commit f504c07
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 38 deletions.
136 changes: 99 additions & 37 deletions root/usr/bin/togo
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Application:
# Set up some class-wide defaults
path_root = os.path.abspath(os.path.curdir)
path_database = os.path.join(path_root, APPLICATION_DATABASE_NAME)
preference_path_database = os.path.join(os.path.expanduser('~/.togo'), 'preferences.db')
path_preference_database = os.path.join(os.path.expanduser('~/.togo'), 'preferences.db')

def __init__(self):
""" Application initialization """
Expand Down Expand Up @@ -148,24 +148,34 @@ class Application:
help="Specify directories to exclude")

# Create the file flag parser and subparser
p_file_flag = sp_file.add_parser('flag', help="Flag commands")
p_file_flag = sp_file.add_parser('flag', help="Flag files")
sp_file_flag = p_file_flag.add_subparsers(dest="sp_file_flag")

# Create the file flag normal parser and subparser
p_file_flag_normal = sp_file_flag.add_parser('normal', help="Flag file(s) as normal")
p_file_flag_normal.add_argument('file_flag_normal_files', metavar="files",
p_file_flag_normal = sp_file_flag.add_parser('normal', help="DEPRECATED: Use 'togo file unflag <file(s)>'")
p_file_flag_normal.add_argument('file_flag_files', metavar="files",
nargs='*', help="Specify files to flag")

# Create the file flag config parser and subparser
p_file_flag_config = sp_file_flag.add_parser('config', help="Flag file(s) as %%config")
p_file_flag_config.add_argument('file_flag_config_files', metavar="files",
p_file_flag_config.add_argument('file_flag_files', metavar="files",
nargs='*', help="Specify files to flag")

# Create the file flag config(noreplace) parser and subparser
p_file_flag_config = sp_file_flag.add_parser('config-nr', help="Flag file(s) as %%config(noreplace)")
p_file_flag_config.add_argument('file_flag_files', metavar="files",
nargs='*', help="Specify files to flag")

# Create the file flag doc parser and subparser
p_file_flag_doc = sp_file_flag.add_parser('doc', help="Flag file(s) as %%doc")
p_file_flag_doc.add_argument('file_flag_doc_files', metavar="files",
p_file_flag_doc.add_argument('file_flag_files', metavar="files",
nargs='*', help="Specify files to flag")

# Create the file unflag parser
p_file_unflag = sp_file.add_parser('unflag', help="Unflag files")
p_file_unflag.add_argument('file_unflag_files', metavar="files",
nargs='*', help="Specify files to unflag")

# Create the file database parser and subparser
p_file_database = sp_file.add_parser('database', help="File database commands")

Expand Down Expand Up @@ -272,8 +282,11 @@ class Application:
# If we're adding files
elif (args.sp_file == 'include'):
self.updateFileDatabase()
for f in args.file_include_files:
self.includeItem(f)
if (args.file_include_files):
for f in args.file_include_files:
self.includeItem(f)
else:
p_file_include.print_help()

# If we're removing files
elif (args.sp_file == 'exclude'):
Expand All @@ -286,16 +299,31 @@ class Application:

# If we're flagging files
elif (args.sp_file == 'flag'):
self.verifyDirectiveData()
self.updateFileDatabase()
if (args.sp_file_flag == 'normal'):
for f in args.file_flag_normal_files:
self.flagItemNormal(f)
elif (args.sp_file_flag == 'config'):
for f in args.file_flag_config_files:
self.flagItemConfig(f)
elif (args.sp_file_flag == 'doc'):
for f in args.file_flag_doc_files:
self.flagItemDoc(f)
if (args.file_flag_files):
if (args.sp_file_flag == 'normal'):
for f in args.file_flag_files:
self.flagItemNormal(f)
elif (args.sp_file_flag == 'config'):
for f in args.file_flag_files:
self.flagItemConfig(f)
elif (args.sp_file_flag == 'config-nr'):
for f in args.file_flag_files:
self.flagItemConfigNoReplace(f)
elif (args.sp_file_flag == 'doc'):
for f in args.file_flag_files:
self.flagItemDoc(f)
else:
p_file_flag.print_help()

# If we're unflagging files
elif (args.sp_file == 'unflag'):
if (args.file_unflag_files):
for f in args.file_unflag_files:
self.unflagItem(f)
else:
p_file_unflag.print_help()

# If we're messing with the file database
elif (args.sp_file == 'database'):
Expand Down Expand Up @@ -340,12 +368,12 @@ class Application:

# Check to see if the preference database exists
# If it doesn't, set it to be created
Dir(os.path.split(self.preference_path_database)[0])
if not (os.path.exists(self.preference_path_database)):
Dir(os.path.split(self.path_preference_database)[0])
if not (os.path.exists(self.path_preference_database)):
initialize = True

# Set up the connection information for the sql object
connection_string = 'sqlite://%s' % (self.preference_path_database)
connection_string = 'sqlite://%s' % (self.path_preference_database)
self.connection = connectionForURI(connection_string)
sqlhub.processConnection = self.connection

Expand Down Expand Up @@ -386,7 +414,7 @@ class Application:
self.connection = connectionForURI(connection_string)
sqlhub.processConnection = self.connection
self.transaction = self.connection.transaction()

def initializeDatabase(self):
""" Initializes the package database """
self.connectToDatabase()
Expand Down Expand Up @@ -416,16 +444,33 @@ class Application:
package_path_spec=p.package_path_spec,
package_path_meta=p.package_path_meta,
package_path_rpms=p.package_path_rpms)

# Verify/setup initial data values
self.verifyDirectiveData()

# Initialize the directive types
Directive(name="%config",
description="Configuration files.")
Directive(name="%dir",
description="Directories.")
Directive(name="%doc",
description="Documentation.")
Directive(name="%docdir",
description="Documentation directories.")
def verifyDirectiveData(self):
""" Check the database for inconsistencies and fix any found issues """
self.connectToDatabase()

## Verify the presence of the directive types
# Set up the desired directives
directives = [{'name': '%config',
'description': "Configuration files."},
{'name': '%config(noreplace)',
'description': "Configuration files w/ noreplace modifier."},
{'name': '%dir',
'description': 'Directories.'},
{'name': '%doc',
'description': 'Documentation'},
{'name': '%docdir',
'description': 'Documentation directories.'}]

# Iterate through the directives and add the missing ones
for directive in directives:
log.debug("Searching for: %s" % directive)
if not (list(Directive.selectBy(name=directive['name']))):
log.debug(" Adding directive to database: %s" % (directive['name']))
Directive(name=directive['name'], description=directive['description'])

def createProject(self, name):
""" Creates a new package and package database """
Expand Down Expand Up @@ -553,6 +598,10 @@ class Application:
sys.exit(2)
else:
self.transaction.commit()

def listFiles(self):
p = Package.get(1)
p.listFiles()

def includeItem(self, item):
p = Package.get(1)
Expand All @@ -563,25 +612,33 @@ class Application:
p.excludeItem(item)

def flagItemNormal(self, item):
log.info("DEPRECATED: Please use 'togo file unflag <file(s)>")
p = Package.get(1)
p.unflagItem(item)

def flagItemConfig(self, item):
p = Package.get(1)
p.flagItem(item, "%config")

def flagItemConfigNoReplace(self, item):
p = Package.get(1)
p.flagItem(item, "%config(noreplace)")

def flagItemDoc(self, item):
p = Package.get(1)
p.flagItem(item, "%doc")

def listFiles(self):
def unflagItem(self, item):
p = Package.get(1)
p.listFiles()
p.unflagItem(item)

def clearAllFlags(self):
p = Package.get(1)
p.clearAllFlags()


def fileChown(self, user_group, item):
p = Package.get(1)
p.fileChown(user_group, item)

# Define the Preference object
class Preference(SQLObject):
Expand All @@ -603,6 +660,7 @@ class Package(SQLObject):
spec_section_extension = ''

def _init(self, *args, **keys):

SQLObject._init(self, *args, **keys)

self.spec_var_name = self.package_name
Expand Down Expand Up @@ -977,7 +1035,7 @@ class Package(SQLObject):
break
def unflagItem(self, item):
item = self.getPackageFile(item)
log.debug("Unflagging '%s'..." % (item.path))
log.info(" Unflagging '%s'" % (item.path))
relative_path = "%s%s" % (self.package_path_root, item.path)
for d in item.directives:
item.removeDirective(d)
Expand All @@ -989,13 +1047,17 @@ class Package(SQLObject):

def flagItem(self, item, directive):
item = self.getPackageFile(item)
log.debug("Flagging '%s' as '%s'..." % (item.path, directive))
log.info(" Flagging '%s' as '%s'" % (item.path, directive))
relative_path = "%s%s" % (self.package_path_root, item.path)

if (directive == "%doc"):
if (os.path.isdir(relative_path)):
directive = "%docdir"
directive = Directive.select(Directive.q.name==directive)[0]

try:
directive = Directive.select(Directive.q.name==directive)[0]
except:
raise Exception("Does not exist.")

# Clear the existing flag
for d in item.directives:
Expand Down
3 changes: 3 additions & 0 deletions spec/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
%changelog
* Sun Mar 18 2018 Gene Reese <[email protected]>
- Added support for %config(noreplace) file flag

* Tue Jul 25 2017 Gene Reese <[email protected]>
- Build package option will now also build the associated source RPM

Expand Down
2 changes: 1 addition & 1 deletion spec/header
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Name: togo
Summary: A quick, easy, and powerful RPM authoring tool

# The version of your package
Version: 2.4
Version: 2.5

# The release number of your package
Release: 1
Expand Down

0 comments on commit f504c07

Please sign in to comment.